Codeforces Round #404 (Div. 2)
来源:互联网 发布:linux 文件空间大小 编辑:程序博客网 时间:2024/05/21 22:48
A.Anton and Polyhedrons
告诉你N个英文单词
每个英文单词代表X面体,统计总共多少面。
#include <cstdio>#include <string>#include <map>#include <iostream> using namespace std;map<string,int> mp;int main(){ mp.clear(); mp["Tetrahedron"]=4; mp["Cube"]=6; mp["Octahedron"]=8; mp["Dodecahedron"]=12; mp["Icosahedron"]=20; int n,ans=0; string st; cin>>n; for(int i=1;i<=n;i++){ cin>>st; ans+=mp[st]; } cout<<ans<<endl; return 0;}
B.Anton and Classes
总共两种课,n种A课,m种B课,给定时间段,两种课都要上且仅要上一次。求中间最多相差几分钟。
若无相差,则答案为0。
#include <bits/stdc++.h>using namespace std;int main(){ int n,m,l,r; int Maxn=-INT_MAX,Maxm=-INT_MAX,Minn=INT_MAX,Minm=INT_MAX; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&l,&r); Maxn=max(Maxn,l); Minn=min(Minn,r); } scanf("%d",&m); for(int i=1;i<=m;i++){ scanf("%d%d",&l,&r); Maxm=max(Maxm,l); Minm=min(Minm,r); } int ans=-INT_MAX; ans=max(ans,Maxm-Minn); ans=max(ans,Maxn-Minm); printf("%d\n",ans>0?ans:0); return 0;}
C.Anton and Fairy Tale
一个一开始为有n个物品的且最大容量为n的仓库,每天会补充m个物品。第i天会来i个小鸟,每个小鸟会取走一个物品。求第几天仓库会空。
首先考虑m>n的时候,每天都会补满,只有第n天一次拿完才行,这就是所谓的X点。
然后,n>m的时候,
前m天肯定会补满。则从第m天向后考虑。
则
解出x正解上取整+m就行了。
以为会爆炸,就用了java写完才发现不会爆。
import java.math.*;import java.util.*;public class Main{ public static void main(String [ ] arguments){ Scanner cin = new Scanner(System.in); BigInteger n,m; n=cin.nextBigInteger(); m=cin.nextBigInteger(); BigInteger tmp = m.add(BigInteger.valueOf(-1).multiply(n)); BigInteger Square=BigInteger.ONE.add(BigInteger.valueOf(-8).multiply(tmp)); BigInteger L,R,ans=BigInteger.valueOf(0); L=BigInteger.ONE;R=Square; while(L.compareTo(R)<=0){ BigInteger Mid=L.add(R); Mid=Mid.divide(BigInteger.valueOf(2)); BigInteger t = Mid.multiply(Mid); if(t.compareTo(Square)<=0){ ans = Mid; L = Mid.add(BigInteger.ONE); } else { R = Mid.add(BigInteger.valueOf(-1)); } } BigInteger tt=ans.multiply(ans); ans = ans.add(BigInteger.valueOf(-3)); ans = ans.divide(BigInteger.valueOf(2)); if(tt.compareTo(Square)<0){ ans=ans.add(BigInteger.ONE); } ans = ans.add(BigInteger.ONE); if(n.compareTo(m)>=0)System.out.println(ans.add(m)); else System.out.println(n); }}
Memory 2017/3/16 12:20:34#include<bits/stdc++.h>using namespace std;#define LL long longint main(){ LL n,m,ans; scanf("%I64d%I64d",&n,&m); if(n>=m){ LL t=(LL)ceil((sqrtl(1+8*(n-m))-1)/2); ans=m+t; } else{ ans=n; } printf("%I64d",ans); return 0;}
D.Anton and School - 2
给定一个只包含”(“、”)”的序列,求其中形如(())这样长度为偶数,左边半边全是(,右边半边全是)的子序列的个数。
组合数学,先预处理好C(n,m)。1e9+7是一个质数,直接用费马小定理求逆元,用二分快速幂即可。
#include<bits/stdc++.h>using namespace std;#define LL long longconst int N = 200005;const LL mod = 1000000007LL;LL fac[N],inv[N];char s[N];int L[N],R[N];LL power(LL a,LL k){ LL ret=1,base=a; while(k) { if(k & 1) ret = ret * base % mod; base = base * base % mod; k >>= 1; } return ret;}void init(){ fac[0]=1; for(int i=1;i<N;i++) fac[i] = fac[i-1] * i % mod; inv[N-1]=power(fac[N-1],mod-2); for(int i=N-2;i>=0;i--) inv[i] = inv[i+1] * (i + 1) % mod;}LL C(int n, int m) { if(m<0) return 0; if(n<m) return 0; return fac[n] * inv[m] % mod * inv[n-m] % mod;}int main(){ init(); scanf("%s",s+1); int n=strlen(s+1); for(int i=1;i<=n;i++) L[i] = (s[i] == '(') ? L[i-1] + 1 : L[i-1]; for(int i=n;i>=1;i--) R[i] = (s[i] == ')') ? R[i+1] + 1 : R[i+1]; LL ans = 0; for(int i=1;i<=n;i++) if(s[i]=='('){ ans = (ans + C(L[i] - 1 + R[i], R[i] - 1)) % mod; } cout<<ans<<endl; return 0;}
1 0
- Codeforces Round #404 (Div. 2)
- Codeforces Round #404 (Div. 2)
- Codeforces Round #404 (Div. 2)
- Codeforces Round #404 (Div. 2)
- Codeforces Round #404 (Div. 2) 题解
- Codeforces Round #404 (Div. 2) A题
- Codeforces Round #404 (Div. 2) B题
- Codeforces Round #404 (Div. 2) C题
- Codeforces Round #404 (Div. 2) A&B
- Codeforces Round #404 (Div. 2)(A+B)
- Codeforces Round #404 (Div. 2) 题解(待续)
- 贪心-Codeforces Round #404 (Div. 2)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- linux笔记-高级网络配置
- 1130. Infix Expression (25)
- DSP技术相关
- php操作memcache
- 交换排序之冒泡排序
- Codeforces Round #404 (Div. 2)
- 近来ROS学习总结及效果展示
- OpenLayers学习笔记(0)
- 2017-03-15和16第9天下午和第十天多线程
- TCP拥塞控制算法纵横谈-BBR vs Reno/CUBIC
- Redis百亿级Key存储方案
- PAT (Basic Level) Practise (中文)1045快速排序(25)
- A*
- 设计模式C++实现(11)——装饰模式