标签:rip put cout 保存 使用 include 长度 inpu acs
DaHaoGeJiuShiYiGeRuoJi DaHaoGeJiuShiYiGeRuoJi DaHaoGeJiuShiYiGeRuoJi
水题直接过(不过我WA了一次,看题太快只输出一次 555555):
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int main(){ 5 cout << "DaHaoGeJiuShiYiGeRuoJi" << endl; 6 cout << "DaHaoGeJiuShiYiGeRuoJi" << endl; 7 cout << "DaHaoGeJiuShiYiGeRuoJi" << endl; 8 return 0; 9 }
YYYS
2
这题又读错题,WA了一次,看成可以改变多次,其实只可以改变一次。直接遍历看有没有YYY或者SSS就行了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int main(){ 5 string s; 6 while(cin >> s){ 7 int ans = 0, flag = 0; 8 int len = s.length(); 9 for(int i = 0; i < len-1; i ++){ 10 if(s[i] == ‘Y‘ && s[i+1] == ‘S‘){ 11 ans ++; 12 } 13 } 14 for(int i = 0; i < len-2; i ++){ 15 if(s[i] == ‘Y‘ && s[i+1] == ‘Y‘ && s[i+2] ==‘Y‘){ 16 flag = 1; 17 } 18 if(s[i] == ‘S‘ && s[i+1] ==‘S‘ && s[i+2] == ‘S‘){ 19 flag = 1; 20 } 21 } 22 if(flag) ans++; 23 cout << ans << endl; 24 } 25 return 0; 26 }
4 4 1 Taidi 100 100 90 90 2 Dahaoge 60 60 70 60 3 Yeshen 90 90 100 100 4 Wangpangzi 50 60 100 80
1 Taidi 100 100 90 90 Sum = 380 Ranking = 1 3 Yeshen 90 90 100 100 Sum = 380 Ranking = 1 4 Wangpangzi 50 60 100 80 Sum = 290 Ranking = 3 2 Dahaoge 60 60 70 60 Sum = 250 Ranking = 4
完全考察写代码能力,不过也WA了一次,没看清(如果总分相同就按学号从小到大输出)这句话,一开始没找出问题所在就直接做后面的题目了,最后回来做时才注意到,然后把
1 return a.sum > b.sum;
改成:
1 if(a.sum != b.sum) return a.sum > b.sum; 2 else return a.id < b.id;
就AC了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 struct Nod{ 5 int id; 6 char s[25]; 7 int k[110]; 8 int sum; 9 int flag; 10 }; 11 int n,m; 12 bool cmp(Nod a, Nod b){ 13 if(a.sum != b.sum) return a.sum > b.sum; 14 else return a.id < b.id; 15 } 16 int main(){ 17 while(~scanf("%d%d",&n,&m)){ 18 Nod nod[n+1]; 19 for(int i = 0; i < n; i ++){ 20 scanf("%d%s",&nod[i].id ,nod[i].s); 21 nod[i].sum = 0; 22 for(int j = 0; j < m; j ++){ 23 scanf("%d",&nod[i].k[j]); 24 nod[i].sum += nod[i].k[j]; 25 } 26 } 27 sort(nod, nod+n,cmp); 28 nod[0].flag = 1; 29 for(int i = 1; i < n; i ++){ 30 if(nod[i].sum == nod[i-1].sum){ 31 nod[i].flag = nod[i-1].flag; 32 }else{ 33 nod[i].flag = i + 1; 34 } 35 } 36 for(int i = 0; i < n; i ++){ 37 printf("%d %s ",nod[i].id,nod[i].s); 38 for(int j = 0; j < m; j ++){ 39 printf("%d ",nod[i].k[j]); 40 } 41 printf("Sum = %d Ranking = %d\n",nod[i].sum,nod[i].flag); 42 43 } 44 } 45 return 0; 46 }
100 4 10 9 5 4 8 5 20 50
13.0000
简单的贪心问题,每次跳单价最小的拿就行了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 struct Nod{ 5 int p, w; 6 }nod[1010]; 7 bool cmp(Nod a, Nod b){ 8 return a.p < b.p; 9 } 10 int main(){ 11 int n, m; 12 while(~scanf("%d%d",&n,&m)){ 13 for(int i = 0; i < m; i ++){ 14 cin >> nod[i].p >> nod[i].w; 15 } 16 double sum = 0; 17 sort(nod,nod+m,cmp); 18 for(int i = 0; i < m; i ++){ 19 // cout << n << ‘ ‘ << nod[i].p << endl; 20 // cout << sum << endl; 21 if(nod[i].p*nod[i].w <= n){ 22 sum += nod[i].w; 23 n = n - nod[i].p*nod[i].w; 24 }else{ 25 sum += n*1.0/nod[i].p*1.0; 26 break; 27 } 28 } 29 printf("%.4lf\n",sum); 30 } 31 return 0; 32 }
5 1 7 2 11 15 6 100 100 100 100 100 100 3 1 2 3
3 1 3
找递增区间最大的就行。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 1e5+10; 5 int a[N]; 6 int main(){ 7 int n; 8 while(~scanf("%d",&n)){ 9 memset(a,0,sizeof(a)); 10 scanf("\n%d",&a[0]); 11 for(int i = 1; i < n; i ++){ 12 scanf("%d",&a[i]); 13 } 14 int maxn = 1, ans = 1; 15 for(int i = 0; i < n; i ++){ 16 if(a[i] < a[i+1]){ 17 ans++; 18 }else{ 19 if(ans > maxn){ 20 maxn = ans; 21 } 22 ans = 1; 23 } 24 } 25 printf("%d\n",maxn); 26 } 27 return 0; 28 }
6 4 1 2 2 1 3 3 1 2 3 1 3 2 2 2 4 3 3 1 2 4 1 3 1 1
2
这题看成求和就行,每行输入一个数,就把它和前面的数相加,放在map里,最后要把总和去掉。然后找里面出现次数最大的,在把n减去它就行了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int n, m; 5 map<int,int> mp; 6 int main(){ 7 while(~scanf("%d",&n)){ 8 mp.clear(); 9 int k; 10 for(int i = 0; i < n; i ++){ 11 int tmp, sum = 0; 12 scanf("%d",&m); 13 for(int i = 0 ; i < m; i ++){ 14 scanf("%d",&tmp); 15 sum+=tmp; 16 mp[sum] ++; 17 } 18 k = sum; 19 } 20 mp.erase(k); 21 map<int,int>::iterator it = mp.begin(); 22 // for(; it != mp.end(); ++ it){ 23 // cout << (*it).first << ‘ ‘ << (*it).second<<endl; 24 // } 25 // it = mp.begin(); 26 int maxn = (*it).second; 27 it++; 28 for(; it != mp.end(); ++it){ 29 int ans = (*it).second; 30 if( ans > maxn ){ 31 maxn = (*it).second; 32 } 33 } 34 printf("%d\n",n - maxn); 35 } 36 return 0; 37 }
1 2
1 2
这题我算没做出来,,因为我打表了,从网上看到一个好理解的题解,就是把它看成万进制,其实就是大数乘以小数的计算。
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 1e4; 4 void factorial(int n){ 5 int a[N]; 6 a[0] = 1; 7 int res = 0; 8 for(int i = 1; i <= n; i ++){ 9 int flag = 0; 10 for(int j = 0; j <= res; j ++){ 11 a[j] = a[j]*i + flag; 12 flag = a[j]/10000; 13 a[j]%=10000; 14 } 15 if(flag > 0){ 16 a[++res] = flag; 17 } 18 } 19 cout << a[res]; 20 for(int i = res-1; i >= 0; i--){ 21 cout << setw(4) << setfill(‘0‘) << a[i]; 22 } 23 cout << endl; 24 } 25 int main(){ 26 int n; 27 while(~scanf("%d",&n)){ 28 factorial(n); 29 } 30 return 0; 31 }
Jxnu Group Programming Ladder Tournament 2017
标签:rip put cout 保存 使用 include 长度 inpu acs
原文地址:http://www.cnblogs.com/xingkongyihao/p/6804287.html