Codeforces Beta Round#2
作者:互联网
Codeforces Beta Round#2
http://codeforces.com/contest/2
A
模拟题
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 map<string,ll>mp; 6 struct sair{ 7 string str; 8 int id; 9 ll num; 10 }a[1005]; 11 12 bool cmp(sair a,sair b){ 13 if(a.num==b.num) return a.id<b.id; 14 return a.num>b.num; 15 } 16 17 int main(){ 18 19 int n; 20 cin>>n; 21 string ans; 22 ll Max=-0x3f3f3f3f; 23 for(int i=1;i<=n;i++){ 24 cin>>a[i].str>>a[i].num; 25 a[i].id=i; 26 } 27 for(int i=1;i<=n;i++){ 28 mp[a[i].str]+=a[i].num; 29 a[i].num=mp[a[i].str]; 30 } 31 for(int i=1;i<=n;i++){ 32 if(mp[a[i].str]>Max){ 33 Max=mp[a[i].str]; 34 } 35 } 36 sort(a+1,a+n+1,cmp); 37 map<string,ll>tmp; 38 for(int i=1;i<=n;i++){ 39 if(mp[a[i].str]==Max){ 40 tmp[a[i].str]=1; 41 } 42 } 43 int idmin=0x3f3f3f3f; 44 for(int i=1;i<=n;i++){ 45 if(tmp[a[i].str]==1){ 46 if(idmin>a[i].id&&a[i].num>=Max){ 47 idmin=a[i].id; 48 ans=a[i].str; 49 } 50 } 51 } 52 cout<<ans<<endl; 53 //system("pause"); 54 55 }View Code
B
DP
能让末尾有0的情况是由2的倍数和5的倍数相乘,所以只要预处理出每个数中因子为2的个数和因子为5的个数,取最小值DP即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 typedef long long ll; 6 7 int n; 8 int dp[1005][1005][2];///dp[i][j][0] 表示2的数量,dp[i][j][1] 表示5的数量 9 int pre[1005][1005][2]; 10 11 void print(int i,int j,int k,int flag){ 12 if(i==1&&j==1); 13 else if(i==1) print(i,j-1,k,0); 14 else if(j==1) print(i-1,j,k,1); 15 else{ 16 if(dp[i][j][k]==dp[i][j-1][k]+pre[i][j][k]) 17 print(i,j-1,k,0); 18 else 19 print(i-1,j,k,1); 20 } 21 if(flag==2) return; 22 cout<<(flag?"D":"R"); 23 } 24 25 int main(){ 26 #ifndef ONLINE_JUDGE 27 freopen("1.txt","r",stdin); 28 #endif 29 std::ios::sync_with_stdio(false); 30 cin>>n; 31 int num,tmp; 32 int x=-1,y=-1; 33 memset(dp,0x3f,sizeof(dp)); 34 for(int i=1;i<=n;i++){ 35 for(int j=1;j<=n;j++){ 36 cin>>num; 37 if(!num){ 38 pre[i][j][0]++; 39 pre[i][j][1]++; 40 x=i,y=j; 41 continue; 42 } 43 tmp=num; 44 while(tmp%2==0){ 45 pre[i][j][0]++; 46 tmp/=2; 47 } 48 tmp=num; 49 while(tmp%5==0){ 50 pre[i][j][1]++; 51 tmp/=5; 52 } 53 } 54 } 55 56 for(int i=1;i<=n;i++){ 57 for(int j=1;j<=n;j++){ 58 for(int k=0;k<2;k++){ 59 if(i>1){ 60 dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]); 61 } 62 if(j>1){ 63 dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k]); 64 } 65 if( i==1 && j==1 ){ 66 dp[i][j][k]=0; 67 } 68 dp[i][j][k]+=pre[i][j][k]; 69 } 70 } 71 } 72 int ans=min(dp[n][n][0],dp[n][n][1]); 73 if(x!=-1&&y!=-1&&ans>=1){ 74 cout<<1<<endl; 75 for(int i=1;i<x;i++){ 76 cout<<"D"; 77 } 78 for(int i=1;i<y;i++){ 79 cout<<"R"; 80 } 81 for(int i=x;i<n;i++){ 82 cout<<"D"; 83 } 84 for(int i=y;i<n;i++){ 85 cout<<"R"; 86 } 87 cout<<endl; 88 } 89 else{ 90 cout<<ans<<endl; 91 if(dp[n][n][0]>dp[n][n][1]){ 92 print(n,n,1,2); 93 } 94 else{ 95 print(n,n,0,2); 96 } 97 cout<<endl; 98 } 99 return 0; 100 }View Code
C
几何题+模拟退火
题意: 找一个点对每个圆切线的角度一样,如果有多个,就找角度最大的点
思路:asin(L/r) 只要L/r一样,它们的角度一定一样,所以用模拟退火枚举就好,感觉和2018icpc南京站的题很像
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 8 struct circle{ 9 double x,y,r; 10 }c[5]; 11 12 double angle[5]; 13 14 double Check(double x,double y){ 15 for(int i=0;i<3;i++){ 16 angle[i]=sqrt(sqr(x-c[i].x)+sqr(y-c[i].y))/c[i].r; 17 } 18 double ans=0; 19 for(int i=0;i<3;i++){ 20 ans+=sqr(angle[i]-angle[(i+1)%3]); 21 } 22 return ans; 23 } 24 25 int main(){ 26 #ifndef ONLINE_JUDGE 27 freopen("1.txt","r",stdin); 28 #endif 29 for(int i=0;i<3;i++){ 30 scanf("%lf %lf %lf",&c[i].x,&c[i].y,&c[i].r); 31 } 32 double ansx,ansy; 33 ansx=(c[0].x+c[1].x+c[2].x)/3; 34 ansy=(c[0].y+c[1].y+c[2].y)/3; 35 double step=1.0; 36 int flag; 37 double tmp; 38 while(step>1e-5){ 39 flag=0; 40 tmp=Check(ansx,ansy); 41 if(tmp>Check(ansx+step,ansy)) ansx+=step,flag=1; 42 else if(tmp>Check(ansx-step,ansy)) ansx-=step,flag=1; 43 else if(tmp>Check(ansx,ansy+step)) ansy+=step,flag=1; 44 else if(tmp>Check(ansx,ansy-step)) ansy-=step,flag=1; 45 if(!flag) step*=0.8; 46 } 47 if(Check(ansx,ansy)<1e-5) printf("%.6f %.6f\n",ansx,ansy); 48 49 }View Code
标签:tmp,ansy,int,Codeforces,Beta,num,step,Round,dp 来源: https://www.cnblogs.com/Fighting-sh/p/10335911.html