16.7.21
2016-07-21 16:57
232 查看
//今日代码
2016-07-21 training
(A题虽然比赛时没有打出来orz 题意是有7个英雄打3个怪,要分成3队求满足题意的最优。解法是因为数据很小直接for7遍,枚举每个人在哪个队。7个for的写法有点难看,另一种就是1个for从1到3^7,表示成3进制就能得出每个人在哪个队伍。)
B. Falling Anvils
(保证方程有实根则有p - 4q >= 0,答案即给定坐标范围内的几何概率)
D. Panoramix’s Prediction
(求b是否是a的下一个相邻素数)
E. Depression
(从00:00顺时针拨到给定时间,分针和时针需要转过的角度。注意4:30这样时针指在4和5之间。)
F. Magical Array
(连续区间中的一串数字的最大最小值相等则被认为是有魔力的,求有魔力的子串个数。即求区间连续且每个数字都相等的子串个数。可知相邻相等个数为n时答案即为n+(n-1)+…+1)
I. Toy Army
(因为都是偶数,显然要保证被击中的人数最多,则双方各用一半的人数击打对方一半人,最终留下1/4的人。//请允许给出题人一个微笑脸。)
2016-07-21 training
(A题虽然比赛时没有打出来orz 题意是有7个英雄打3个怪,要分成3队求满足题意的最优。解法是因为数据很小直接for7遍,枚举每个人在哪个队。7个for的写法有点难看,另一种就是1个for从1到3^7,表示成3进制就能得出每个人在哪个队伍。)
B. Falling Anvils
(保证方程有实根则有p - 4q >= 0,答案即给定坐标范围内的几何概率)
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<cstring> #include<map> #define LL long long #define INF 0x1f1f1f1f using namespace std; int main() { freopen("xx.in","r",stdin); freopen("xx.out","w",stdout); int t; cin >> t; while(t--) { double a,b; scanf("%lf%lf",&a, &b); double y = a/4; double ans = 0; double sum = 2*b*a; double ans1 = (a*y)/2+a*b; double ans2 = ((a-4*b)+a)*b/2+a*b; if(b == 0) cout << 1 << endl; else if(a == 0) cout << 0.5 << endl; else { if(y<=b) ans = ans1/sum; else ans = ans2/sum; cout << ans << endl; } } return 0; }
D. Panoramix’s Prediction
(求b是否是a的下一个相邻素数)
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<cstring> #include<map> #define LL long long #define INF 0x1f1f1f1f using namespace std; bool check(int num)//ispri { for(int i = 2; i<= sqrt(num) ;i++) if(num%i == 0) return false; return true; } int main() { freopen("xx.in","r",stdin); freopen("xx.out","w",stdout); int a,b; cin >> a >> b; if(check(b) == false) cout << "NO" << endl; else { bool flag = false; for(int i = a+1; i < b; i++) { if(check(i) == true) { cout << "NO" << endl; flag = true; break; } } if(!flag) cout << "YES" <<endl; } return 0; }
E. Depression
(从00:00顺时针拨到给定时间,分针和时针需要转过的角度。注意4:30这样时针指在4和5之间。)
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<cstring> #include<map> #define LL long long #define INF 0x1f1f1f1f using namespace std; int main() { freopen("xx.in","r",stdin); freopen("xx.out","w",stdout); double h,m; scanf("%lf:%lf",&h,&m); h+=m/60; if(h>=12) h-=12; cout << h/12*360 <<" "<<m/60*360<< endl; return 0; }
F. Magical Array
(连续区间中的一串数字的最大最小值相等则被认为是有魔力的,求有魔力的子串个数。即求区间连续且每个数字都相等的子串个数。可知相邻相等个数为n时答案即为n+(n-1)+…+1)
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<cstring> #include<map> #define LL long long #define INF 0x1f1f1f1f using namespace std; LL arr[100010]; map<int, int> mm; int main() { freopen("xx.in","r",stdin); freopen("xx.out","w",stdout); int n; cin >> n; for(int i = 0; i < n; i++) scanf("%I64d",&arr[i]); LL ans = 0; for(int i = 0; i < n;) { LL cnt = 1; int j = i+1; while(arr[i] == arr[j] && j < n) { cnt++; j++; } ans+=(cnt+1)*cnt/2; i = j; } cout << ans << endl; return 0; }
I. Toy Army
(因为都是偶数,显然要保证被击中的人数最多,则双方各用一半的人数击打对方一半人,最终留下1/4的人。//请允许给出题人一个微笑脸。)
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<cstring> #include<map> #define LL long long #define INF 0x1f1f1f1f using namespace std; int main() { freopen("xx.in","r",stdin); freopen("xx.out","w",stdout); LL n; cin >> n; cout << 2*n/4*3 << endl; return 0; }
相关文章推荐
- leetcode 122
- JVM(java 虚拟机)内存设置
- Java @Override报错
- 关于disconf linux下报cannot get host info的问题
- 怎样合并字典最符合Python语言习惯?
- 7月
- 关于zepto.js的移动端拖拽写法
- linux下使用yum安装svn
- 做一个GPSCar类,要求继承Car类,并实现GPS接口
- 使用java正则表达式去掉多余的.与0
- hdu1006 Tick and Tick
- Keep On Movin
- Log4j 日志文件Linux/Mac/Windows通用存放位置设置
- linux c下简单实现服务端与多客户端同时连接
- 构建属于自己的elasticsearch Docker镜像
- tomcat 修改默认字符集
- Oracle SOA Suite OverView
- 虚函数与纯虚函数的区别
- android AsyncTask
- js图片轮播可控制是否循环轮播,点击左右按钮切换