CQUPT WEEKLY TRAINING (4)DIV2 解题报告
来源:互联网 发布:平面设计学哪些软件 编辑:程序博客网 时间:2024/06/07 16:13
第一题:就是第n项等于前6项和。
注意限时比较紧,只有0.5s。所以用循环把结果存入数组。递归估计就TLE了
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <iostream>using namespace std;typedef long long LL;const int MOD = 10000007;LL f[10005];int main(){ int t; int kase=1; scanf("%d",&t); int n; while(t--) { cin>>f[0]>>f[1]>>f[2]>>f[3]>>f[4]>>f[5]>>n; for(int i=6;i<=n;i++) { f[i]=(f[i-1]+f[i-2]+f[i-3]+f[i-4]+f[i-5]+f[i-6])%MOD; } printf("Case %d: ",kase++); cout<<f[n]%MOD<<endl; }}
第二题:给个棋盘,黑白格相间。问最多能放多少个马,马之间不会打架。。
考虑到,马的走法。我全部放白或者黑就可以了,但是有特殊情况。就是棋盘有一边等于1的时候,全部放上就行。棋盘有一边等于2的时候,我就放一个田字格,中间间隔一个田字格。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;typedef LL long longint main(){ int T; scanf("%d",&T); int cas=0; while(T--) { cas++; int n,m,x,y; scanf("%d%d",&n,&m); if(n>m)swap(n,m); x=n*m; x=x/2; y=n*m-x; y=max(x,y); if(n==1)x=m; if(n==2)x=2*(2*(m/4)+min(2,m%4)); printf("Case %d: %d\n",cas,max(x,y)); } return 0;}
第三题:全部1A,水模拟,读懂题意写写就好了。
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <iostream>using namespace std;int main(){ int t,kase=1,l,r; scanf("%d",&t); while(t--) { scanf("%d%d",&l,&r); if(l>r) { printf("Case %d: %d\n",kase++,(2*l-r)*4+19); continue; } l=max(l,r); printf("Case %d: %d\n",kase++,l*4+19); } return 0;}
第四题:也是水题,判断一下坐标关系就行了。
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <iostream>using namespace std;int main(){ int t,kase=1,x1,x2,y1,y2,m,a,b; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); scanf("%d",&m); printf("Case %d:\n",kase++); while(m--) { scanf("%d%d",&a,&b); if(x1<a&&a<x2&&y1<b&&b<y2) printf("Yes\n"); else printf("No\n"); } }}
第五题:几何题。
如图,就是给大圆的半径和小圆的个数,求小圆半径。
这道题可以二分小圆半径,然后check。
也可以直接找几何关系。从大圆圆心连一条任意小圆的切线,切点连接该小圆圆心,构成一个直角三角形。然后用三角函数列式子就能解了。
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <iostream>using namespace std;const double PI=acos(-1.0);int main(){ int t,kase=1; scanf("%d",&t); double R,n,alpha,r; while(t--) { cin>>R>>n; alpha=PI/n; r=sin(alpha)*R/(1+sin(alpha)); printf("Case %d: %.8lf\n",kase++,r); } return 0;}
第六题:个人认为是好题。
给出一个n,求出一个比他大,且二进制的1的个数相同的第一个数。
硬模拟,我试过几次优化,感觉都不能过。
这里用的STL的next_permutation()就是求出下一个排列。
然后用字符串模拟一下,注意有可能该个数就是最大的排列,它的下一个需要特殊处理一下。
(这道题,理解有困难的,看看STL,string和基础的位运算)
另外gcc内置有几个位运算的函数,我之后尝试下可以不可以过。
给一篇好的位运算的文章:
http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=bitManipulation
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <iostream>using namespace std;int fun(string a){ int ans=1; for(int i=1;i<a.size();i++) { if(a[i]=='0') ans=(ans << 1); else ans=(ans << 1 | 1); } return ans;}int main(){ int t,kase=1; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); string str=""; while(n) { if(n&1) str.insert(0,"1"); else str.insert(0,"0"); n/=2; } if(!next_permutation(str.begin(),str.end())) { str.insert(0,"10"); str.erase(str.size()-1,1); } printf("Case %d: %d\n",kase++,fun(str)); }}
0 0
- CQUPT WEEKLY TRAINING (4)DIV2 解题报告
- CQUPT WEEKLY TRAINING (2)DIV2 解题报告
- CQUPT WEEKLY TRAINING (5)DIV2 解题报告
- CQUPT WEEKLY TRAINING (6)DIV2 解题报告
- CQUPT WEEKLY TRAINING (7)DIV2 解题报告
- CQUPT WEEKLY TRAINING (1)解题报告
- CQUPT WEEKLY TRAINING (3)解题报告
- Mango Weekly Training Round #3 解题报告
- Mango Weekly Training Round #6 解题报告
- 2015 CQUPT WEEKLY TRAINING (1)题解和专题内容推荐
- LeetCode Weekly Contest 56 解题报告
- codeforces #133 div2 解题报告
- codeforces #134 div2 解题报告
- SRM 556 DIV2 解题报告
- codeforce 192 div2解题报告
- 130720CF div2解题报告
- [Codeforces]Round246 div2 解题报告
- codeforces#254DIV2解题报告
- 金色十月线上编程比赛第一题:小女孩数数
- Ubuntu配置Tomcat
- mina session
- 实例解析linux内核I2C体系结构
- session.write类型引发的思考---Mina Session.write流程探索.doc
- CQUPT WEEKLY TRAINING (4)DIV2 解题报告
- 第10周项目2加密数字1-9
- 【TMT时代】:因为【不甘心】而成就【顶级“黑客”】
- Android 亲身经历面试题总结(第一回合)
- hibernate映射关系详解
- 函数值传递,指针传递与引用传递的区别 及解释。
- POJ3258 River Hopscotch
- 网贷推广宝致英邦投资推广运营专员的一封信
- 网贷推广宝致旺财谷推广运营专员的一封信