HDU 1021 Fibonacci Again
2015-08-04 19:23
357 查看
题目地址:点击打开链接
思路:数到后面会越来越大,不可能保存,只要求能否被三整除,简单的同余就可以,数据也没预处理也过了,看到大神直接看n就能判断能否被3整除,叼爆了,贴一下,有时间看一下
AC代码:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,i;
vector<int> v(1000000);
while(cin>>n)
{
v[0] = 7;
v[1] = 11;
for(i=2; i<=n; i++)
{
v[i] = v[i-1] % 3 + v[i-2] % 3;
}
if(v
% 3 == 0)
{
cout<<"yes"<<endl;
}
else
cout<<"no"<<endl;
}
return 0;
}
大神代码:
#include<stdio.h>
int main()
{
long n;
while(scanf("%ld",&n) != EOF)
if (n%8==2 || n%8==6)
printf("yes\n");
else
printf("no\n");
return 0;
}
思路:数到后面会越来越大,不可能保存,只要求能否被三整除,简单的同余就可以,数据也没预处理也过了,看到大神直接看n就能判断能否被3整除,叼爆了,贴一下,有时间看一下
AC代码:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,i;
vector<int> v(1000000);
while(cin>>n)
{
v[0] = 7;
v[1] = 11;
for(i=2; i<=n; i++)
{
v[i] = v[i-1] % 3 + v[i-2] % 3;
}
if(v
% 3 == 0)
{
cout<<"yes"<<endl;
}
else
cout<<"no"<<endl;
}
return 0;
}
大神代码:
#include<stdio.h>
int main()
{
long n;
while(scanf("%ld",&n) != EOF)
if (n%8==2 || n%8==6)
printf("yes\n");
else
printf("no\n");
return 0;
}
相关文章推荐
- 2015 Multi-University Training Contest 5
- Codeforces gym 100685 E. Epic Fail of a Genie 贪心
- more detail pxe deploy in ironic
- HDU 5347 MZL's chemistry (2015 Multi-University Training Contest 5 2015多校联合)
- leetcode--Contains Duplicate III
- HDU 5349 MZL's simple problem (2015 Multi-University Training Contest 5 2015多校联合)
- You have new mail
- 2015 Multi-University Training Contest 5
- 如何批量修改AD用户的Email属性
- 如何批量修改AD用户的Email属性
- vim中添加molokai.vim 配色安装
- dao、domain、service、web、vo、Model这些层的功能是什么
- Linq 模糊查询。Countains StartsWith EndsWith Indexof截取字符串,都可以用在Linq查询语句里
- [LeetCode]Container With Most Water
- [AIR] AIR将数据保存并导出为Excel
- aidl
- 推荐一个Monokai风格的EditPlus配色方案
- 2015 HUAS Summer Trainning #4~A
- (FFOS Gecko & Gaia) OTA - 入口
- jetbrains