450B Jzzhu and Sequences 我考研之后做的第一道题
来源:互联网 发布:mac向上箭头怎么打 编辑:程序博客网 时间:2024/06/02 23:59
从考研到现在就没做过题了,一转眼一年半过去了,自己的编程能力真的是飞速下降,如此简单的一道题我却做得如此费劲如此麻烦,哎,以后每天做题,九月之前一定codeforces至少要紫色吧,说正题:
因为计算失误,一开始以为不是从头就是一流为周期的,要自己寻找周期开始的位置,还意淫的用kmp找起始位置(真是好久没做题了,思维僵化啊)
最蛋疼的是算mod的时候,我真是一点编程的思维都没有了,完全模拟自我脑海里的手动计算的方法进行,所以我的代码写的非常湿,非常麻烦,看完网上一些人写的代码我惭愧的不行,好了,忏悔结束。
我还寻找其实点,取mod的模拟手动计算的模式,所以代码很麻烦!
#include<iostream>#include<stdio.h>using namespace std;#define mod 1000000007int abs(int i){ if(i<0) return i*(-1); return i;}int a[100];int main(){// cout<<-200%107<<endl;// freopen("in.txt","r",stdin); int x,y,n; while(scanf("%d %d",&x,&y)!=EOF){ scanf("%d",&n); int temp; a[0]=x;a[1]=y; for(int i=0;i<2;i++){ if(a[i]<0 && a[i]>=(-1)*mod) a[i]+=mod; else{ int t,t1; t=a[i]/mod; t1=a[i]%mod; if(t<0) { t=t*(-1); a[i]=abs((t+1)*mod+a[i])>abs(t1)? abs(t1):abs((t+1)*mod+a[i]); } else a[i]=a[i]%mod; } } for(int i=2;i<100;i++){ a[i]=a[i-1]-a[i-2]; if(a[i]<0 && a[i]>=(-1)*mod) a[i]+=mod; else{ int t,t1; t=a[i]/mod; t1=a[i]%mod; if(t<0) { t=t*(-1); a[i]=abs((t+1)*mod+a[i])>abs(t1)? abs(t1):abs((t+1)*mod+a[i]); } else a[i]=a[i]%mod; } } int st=0,qt=0; int count=0; for(int i=0,j=6;j<100;i++,j++){ if(a[i]==a[j]) count++; else count=0; if(count==6){ st=i+1-6; break; } } if(n<=st) cout<<a[n-1]<<endl; else{ temp=(n-st)%6-1; if(temp==-1) temp=5; temp+=st; printf("%d\n",a[temp]); } }}
0 0
- 450B Jzzhu and Sequences 我考研之后做的第一道题
- B. Jzzhu and Sequences
- B. Jzzhu and Sequences
- Codeforces 450 B. Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CF 450B Jzzhu and Sequences
- CodeForces 450-B. Jzzhu and Sequences
- CodeForces 450B Jzzhu and Sequences
- codeforces 450B Jzzhu and Sequences
- CodeForces-450B Jzzhu and Sequences
- codeforces 450B Jzzhu and Sequences
- CodeForces 450B Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CodeForces 450B-Jzzhu and Sequences
- CF 450B Jzzhu and Sequences
- Codeforce 450B Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- codeforces B. Jzzhu and Sequences
- B - Super long sums
- IOS研究之网络编程(二)-Cocoa Streams使用详解
- 《Spring3.X企业应用开发实战》学习笔记--SpringMVC
- Linux 下编译、安装、配置 QT
- Java面试
- 450B Jzzhu and Sequences 我考研之后做的第一道题
- UVA 101 (暑期-线性表-D-The Blocks Problem)
- 非常难受
- 续前篇---数据挖掘之聚类算法k-mediod(PAM)原理及实现
- HDU3695Computer Virus on Planet Pandora ac自动机版
- Hadoop集群(第5期副刊)_JDK和SSH无密码配置
- sqlite3自增key设定(创建自增字段)
- C++STL之函数对象及谓词
- pomelo+mongodb