首页 > 代码库 > Codeforces 474(#270) 解题报告
Codeforces 474(#270) 解题报告
A:直接贴过来装换
解题代码
1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月06日 星期一 23时28分57秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 26 using namespace std;27 char str[102];28 char tp[4][100] = {"qwertyuiop",29 "asdfghjkl;",30 "zxcvbnm,./",31 };32 int main(){33 scanf("%s",str);34 if(str[0] == ‘L‘)35 {36 scanf("%s",str);37 for(int i = 0;i < strlen(str);i ++)38 {39 for(int j = 0;j <= 2;j ++)40 {41 if(strchr(tp[j],str[i]))42 {43 printf("%c",tp[j][strchr(tp[j],str[i]) - tp[j] +1]);44 }45 }46 }47 }48 else{49 scanf("%s",str);50 for(int i = 0;i < strlen(str);i ++)51 {52 for(int j = 0;j <= 2;j ++)53 {54 if(strchr(tp[j],str[i]))55 {56 printf("%c",tp[j][strchr(tp[j],str[i]) - tp[j] - 1]);57 }58 }59 60 }61 }62 return 0;63 }
B:一个标记或者二分就行,最大1e6的复杂度
解题代码:
1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月06日 星期一 23时39分31秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 26 using namespace std;27 int a[100005];28 int b[100005];29 int n , m ; 30 int find(int x)31 {32 int l = 1; 33 int r = n;34 while(l <= r)35 {36 int mid = (l + r)/2;37 if(a[mid] < x)38 {39 l = mid + 1;40 }else {41 r = mid - 1;42 }43 }44 return l;45 }46 int main(){47 scanf("%d",&n);48 for(int i =1 ;i <= n;i ++)49 { scanf("%d",&a[i]);50 a[i] = a[i-1] + a[i];51 }52 scanf("%d",&m);53 for(int i =1 ;i <= m;i ++)54 {55 scanf("%d",&b[i]);56 printf("%d\n",find(b[i]));57 }58 return 0;59 }
C:知道转换公式以后就是一个手速题
1 // File Name: c.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月07日 星期二 00时41分28秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack> 11 #include<bitset> 12 #include<algorithm> 13 #include<functional> 14 #include<numeric> 15 #include<utility> 16 #include<sstream> 17 #include<iostream> 18 #include<iomanip> 19 #include<cstdio> 20 #include<cmath> 21 #include<cstdlib> 22 #include<cstring> 23 #include<ctime> 24 #define LL long long 25 #define eps 1e-8 26 using namespace std; 27 struct node{ 28 double x,y,a,b; 29 }; 30 node a[5][5]; 31 node change(node tp) 32 { 33 node ans; 34 ans.a = tp.a; 35 ans.b = tp.b; 36 ans.x = tp.a - (tp.y - tp.b); 37 ans.y = tp.b + (tp.x - tp.a); 38 return ans; 39 } 40 int ans[0]; 41 double dis[5][5]; 42 double thedis(double x1, double y1, double x2,double y2) 43 { 44 return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) ; 45 } 46 int mi; 47 bool ok() 48 { 49 node tt[5]; 50 for(int i = 1;i <= 4;i ++) 51 { 52 tt[i] = a[i][ans[i]]; 53 } 54 for(int i = 1;i <= 4;i ++) 55 { 56 for(int j= 1;j <= 4 ; j ++) 57 { 58 dis[i][j] = thedis(tt[i].x,tt[i].y,tt[j].x,tt[j].y); 59 } 60 sort(dis[i] + 1,dis[i] + 1 + 4); 61 } 62 for(int i = 2;i <= 4;i ++) 63 for(int j = 1;j <= 4; j ++) 64 { 65 if(fabs(dis[i][j] - dis[i-1][j]) > eps) 66 return 0 ; 67 } 68 if(fabs(dis[1][4]-0 ) <eps) 69 return 0 ; 70 if(fabs(dis[1][3] - dis[1][2]) > eps) 71 return 0 ; 72 if(fabs(dis[1][3] * sqrt(2) - dis[1][4]) > eps) 73 return 0 ; 74 if(fabs(dis[1][3] - 0 ) < eps) 75 return 0 ; 76 if(fabs(dis[1][2] - 0 ) < eps) 77 return 0 ; 78 /*for(int i = 1;i <= 4;i ++) 79 { 80 for(int j = 1;j <= 4; j ++) 81 printf("%lf ",dis[i][j]); 82 printf("\n"); 83 } 84 for(int i = 1;i<= 4;i ++) 85 printf("%lf %lf\n",tt[i].x,tt[i].y); 86 87 */ 88 return 1; 89 } 90 void dfs(int k) 91 { 92 if(k == 5) 93 { 94 if(ok()) 95 { 96 if(ans[1] + ans[2] + ans[3] + ans[4] - 4< mi) 97 mi = ans[1] + ans[2] + ans[3] + ans[4] -4; 98 //printf("%d %d %d %d\n",ans[1],ans[2],ans[3],ans[4]); 99 }100 return;101 }102 for(int i = 1;i <= 4;i ++)103 {104 ans[k] = i ;105 dfs(k+1);106 }107 }108 int main(){109 int n; 110 scanf("%d",&n);111 while(n--)112 {113 for(int i= 1;i <= 4;i ++)114 scanf("%lf %lf %lf %lf",&a[i][1].x,&a[i][1].y,&a[i][1].a,&a[i][1].b);115 for(int i = 1;i<= 4;i ++ ) 116 {117 for(int j = 2;j <= 4;j ++)118 a[i][j] = change(a[i][j-1]);119 }120 /* for(int i = 1;i<= 4;i ++ ) 121 {122 for(int j = 1;j <= 4;j ++)123 printf("%lf %lf ** ",a[i][j].x,a[i][j].y);124 printf("\n");125 }*/126 mi = 1000; 127 dfs(1);128 if(mi == 1000)129 printf("-1\n");130 else printf("%d\n",mi);131 }132 return 0;133 }
D: dp,考虑最后这一位是R还是W即可
1 // File Name: d.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月07日 星期二 00时21分01秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque>10 #include<stack>11 #include<bitset>12 #include<algorithm>13 #include<functional>14 #include<numeric>15 #include<utility>16 #include<sstream>17 #include<iostream>18 #include<iomanip>19 #include<cstdio>20 #include<cmath>21 #include<cstdlib>22 #include<cstring>23 #include<ctime>24 #define LL long long25 #define maxn 10000426 #define M 100000000727 using namespace std;28 int t, k ;29 30 LL ans[maxn][2];31 LL sum[maxn];32 int main(){33 while(scanf("%d %d",&t,&k) != EOF)34 {35 ans[1][1] = 1;36 ans[0][2] = 1; 37 38 if(k == 1 )39 ans[1][2] = 1;40 else ans[1][2] = 0 ; 41 sum[0] = 0 ;42 sum[1] = ans[1][1] + ans[1][2];43 for(int i = 2; i <= 100000;i ++)44 {45 ans[i][1] = (ans[i-1][1] + ans[i-1][2])%M ;46 if(i >= k )47 ans[i][2] = (ans[i-k][1] + ans[i-k][2])%M;48 else{49 ans[i][2] = 0 ; 50 }51 sum[i] = (sum[i-1] + ans[i][1] + ans[i][2])%M;52 // printf("%I64d\n",sum[i]);53 }54 int a, b; 55 for(int i =1 ;i <= t;i ++)56 {57 scanf("%d %d",&a,&b);58 printf("%I64d\n",((sum[b] - sum[a-1])+ M)%M );59 }60 61 }62 return 0;63 }
Codeforces 474(#270) 解题报告
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。