4 条题解
-
1
刚看到这题可以先用找规律:
#include<bits/stdc++.h> using namespace std; int m,n; int ans; void dfs(int t,int s){ if(t==n+1){ if(s>=0){ ans=min(ans,s); } return; } dfs(t+1,s+t); dfs(t+1,s-t); return; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>m; for(n=1;n<=m;n++){ ans=1e9; dfs(1,0); cout<<n<<' '<<ans<<endl; } return 0; }
输入 20 后可以看见:
1 1 2 1 3 0 4 0 5 1 6 1 7 0 8 0 9 1 10 1 11 0 12 0 13 1 14 1 15 0 16 0 17 1 18 1 19 0 20 0
可发现1,1,0,0交替出现, 可知 n%43||n%40时 答案为 0 n%41||n%42时 答案为 1
可问题来了,n(n<10^2000),如何高精取余?
我们可以把 n 直接看成两位数进行计算,因为 n 十位以上跟 n%4 的结果没关系
所以我们可写出 代码:
#include<bits/stdc++.h> using namespace std; string n; signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n; int x; if(n.size()==1) x=n[0]-'0';//注意特判 else x=(n[n.size()-2]-'0')*10+(n[n.size()-1]-'0'); //cout<<x<<endl; if(x%4==1||x%4==2) putchar('1'); else putchar('0'); return 0; }
喜欢请点个赞!
-
1
#include<bits/stdc++.h> using namespace std; int n,x; string s; int main(){ cin>>s; n=s.size(); if(n>=2) { x=(s[n-2]-'0')*10+s[n-1]-'0'; } else x=s[0]-'0'; if(x==2) { cout<<3; return 0; } if(x%4==1) { cout<<1; return 0; } if(x%4==2) { cout<<1; return 0; } if(x%4==3) { cout<<0; return 0; } if(x%4==0) { cout<<0; return 0; } }
- 1
信息
- ID
- 210
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- (无)
- 递交数
- 273
- 已通过
- 79
- 上传者