Codefroces #404 Div2
分析:把多面体和面数一一对应即可
1 #include<iostream> 2 #include<map> 3 #include<cstring> 4 #include<cstdio> 5 using namespace std; 6 int main() 7 { 8 int T; 9 while(cin>>T){ 10 map<string,int>mp; 11 mp["Tetrahedron"]=4; 12 mp["Cube"]=6; 13 mp["Octahedron"]=8; 14 mp["Dodecahedron"]=12; 15 mp["Icosahedron"]=20; 16 long long sum=0; 17 for(int i=0;i<T;i++){ 18 string s; 19 cin>>s; 20 sum+=mp[s]; 21 } 22 cout<<sum<<endl; 23 } 24 return 0; 25 }
分析:分别统计最早的r1和最晚的l2,以及最早的r2和最晚的l1,求二者的最大值即可
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 const int maxn=200000+10; 7 const int INF=100000000; 8 typedef struct 9 { 10 long long l,r; 11 }point; 12 point p1[maxn],p2[maxn]; 13 bool cmp1(point a,point b){ 14 return a.r<b.r; 15 } 16 bool cmp2(point a,point b){ 17 return a.l>b.l; 18 } 19 int n,m; 20 int main() 21 { 22 while(cin>>n){ 23 long long minx=INF; 24 for(int i=0;i<n;i++){ 25 scanf("%I64d%I64d",&p1[i].l,&p1[i].r); 26 } 27 sort(p1,p1+n,cmp1); 28 cin>>m; 29 for(int i=0;i<m;i++){ 30 scanf("%I64d%I64d",&p2[i].l,&p2[i].r); 31 } 32 sort(p2,p2+m,cmp2); 33 int i=0,j=0; 34 long long ans=0; 35 long long cnt=p2[j].l-p1[i].r; 36 ans=max(ans,cnt); 37 sort(p1,p1+n,cmp2); 38 sort(p2,p2+m,cmp1); 39 long long h=0; 40 h=max(h,(p1[j].l-p2[i].r)); 41 ans=max(h,ans); 42 cout<<ans<<endl; 43 } 44 return 0; 45 }
分析:若对于m>n,直接就是n天,若n>m,则前m天是必须的,后面相当于去寻找一个最小的x,使1+2+3+......+x>(n-m),所以二分答案即可
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 using namespace std; 5 long long n,m; 6 int main() 7 { 8 while(cin>>n>>m){ 9 if(m>n){ 10 cout<<n<<endl; 11 continue; 12 } 13 n-=m; 14 long long l=0,r=2e9; 15 while(l<r){ 16 long long mid=(l+r)>>1; 17 long long ans=(1+mid)*mid/2; 18 if(ans>=n) r=mid; 19 else l=mid+1; 20 } 21 cout<<m+l<<endl; 22 } 23 return 0; 24 }