标签:
算绩点
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 int n; 8 string p[15] = {"A","A-","B+","B","B-", 9 "C+","C","C-","D","D-","F"}; 10 double a[15] = {4.0,3.7,3.3,3.0,2.7,2.3,2.0,1.7, 11 1.3,1.0,0.0}; 12 13 int main(){ 14 while(scanf("%d",&n) != EOF){ 15 int x; 16 char s[105]; 17 double fz = 0.0,fm = 0.0; 18 for(int i = 1;i <= n;i++){ 19 scanf("%d %s",&x,s); 20 getchar(); 21 // printf("s = %s\n",s); 22 if(s[0] == ‘P‘ || s[0] == ‘N‘) continue; 23 for(int j = 0;j < 11;j++){ 24 if(s == p[j]){ 25 // printf("a[%d] = %d p[%d] = %s \n",j,a[j],j,p[j].c_str()); 26 fz += x*a[j]; 27 fm += x; 28 double l = x*a[j]; 29 double r = x; 30 // printf("l = %lf r = %lf \n",l,r); 31 break; 32 } 33 } 34 } 35 if(fz == 0 || fm == 0) puts("0.00"); 36 else{ 37 printf("%.2lf\n",fz/fm); 38 } 39 } 40 return 0; 41 }
练的时候
一直在想BFS,,,好sb啊,
后来他们想出了差不多正确的做法,,,一直wa
贪心
一直让当前的y摁到最接近最终状态的平均数
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 int x,y; 8 9 int main(){ 10 while(scanf("%d %d",&x,&y) != EOF){ 11 if(y < x) { 12 puts("-1"); 13 continue; 14 } 15 double pj = (y+0.99999)/x; 16 int cnt = x-1; 17 double cx = 1.0,cy = 1.0; 18 for(cx = 1;cx <= x;cx++){ 19 int time = pj*cx-cy; 20 cnt += time; 21 cy += 1.0*time; 22 cy += cy/cx; 23 } 24 printf("%d\n",cnt); 25 } 26 return 0; 27 }
插头dp
他俩搞的,,对着挑战写写改改---
居然过了
他俩搞的
贪心
后来看题解说是 树分治
标签:
原文地址:http://www.cnblogs.com/wuyuewoniu/p/4948521.html