码迷,mamicode.com
首页 > 其他好文 > 详细

Jxnu Group Programming Ladder Tournament 2017

时间:2017-05-03 22:51:09      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:rip   put   cout   保存   使用   include   长度   inpu   acs   

L1-1 这是一道简单题

 

Problem Description

大豪哥觉得自己特别的菜,就是个弱鸡,但是大家不承认,所以大豪哥想了一个办法,在学校大屏幕上输出三行“DaHaoGeJiuShiYiGeRuoJi”,这样就可以说明自己是个弱鸡了。可是大豪哥太渣了不会写,你能帮他输出一下吗?

Input

本题无输入

Output

按题目要求输出

Sample Output

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 }

 

L1-2 叶神的字符串

Problem Description

众所周知,ACS协会会长叶神学习特别好,算法能力也强,作为一个弱渣的大豪哥特别崇拜叶神,觉得‘Y’‘S’这两个字符特别厉害,所以大豪哥的一个键盘上就只有Y,S两个键,大豪哥用这个键盘打出了一个字符串s,但是他特别的不满意,所以他想改变字符串s中的一个字符(也可以不改变),使得字符串s中可以截取出最大数量的“YS”

Input

多组输入至文件结尾。
每组测试数据输入一串由‘Y‘,‘S‘组成的字符串。(字符串长度最多为10000)

Output

输出至多一次修改后最多有多少个“YS”

Sample Input

YYYS

Sample Output

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 }

 

L1-3 成绩排名

Problem Description

每次期末考试成绩出来之前的一段时间大豪哥心里都是痛苦的,总感觉自己会在班上排名特别差。所以当成绩出来以后大豪哥想快点知道班上的总排名,以便知道自己的排名。(PS:大豪哥班上有个学霸名叫日天,又名泰迪,不要问我为什么,因为泰迪的行为决定的)

Input

多组测试数据,至文件结尾。
先输入每个班上有n个同学,这个学期有m门课程(1<=n,m<=100)
接下来有n行,每行的输入格式为学号id,姓名name,课程成绩k1,课程成绩k2... ,课程成绩km.(学号在int型范围以内,0<=ki<=100,姓名长度在20个字符以下)

Output

输出班上每个同学排名,并输出总分及排名(如果总分相同就按学号从小到大输出,但是排名还是相同的)输出格式见样例

Sample Input

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

Sample Output

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 }

 

 

L1-4 王胖子买零食

Problem Description

大豪哥有个好朋友叫王胖子,众所周知王胖子特别爱吃零食,比如各种不一样的糖果,辣条呀,可是王胖子每个月用在买零食上的钱不是固定的,但是因为王胖子特别爱吃零食,他希望把自己能花在买吃的钱全部用掉,来换得最多的零食

Input

先输入王胖子有n块钱可以用来买吃的,商场里有m件零食(0<=n,m<=1000)
接下来有m行,每行包括这件零食的单价(元/kg),以及商场有多少kg这种商品
所有输入数据都在int型范围内

Output

输出王胖子最多可以有多少零食(保存4位小数)

Sample Input

100 4
10 9
5 4
8 5
20 50

Sample Output

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 }

 

L1-5 Dada的游戏

Problem Description

Dada无聊时,喜欢做一个游戏,将很多钱分成若干堆排成一列,每堆钱数不固定,谁能找出每堆钱数严格递增的最长区间,谁就是人生赢家了。Dada可能脑子里的水还没干,她找不出来,你来帮她找找吧。

Input

多组输入,至文件结尾。
对于每组数据:
第一行包含一个正整数n(1<=n<=100000),一共有n堆钱。
第二行输入n个正整数a1,a2,...,an (1<=ai<=1000000000),代表每一堆的钱数
大量输入,请使用scanf。

Output

打印严格递增的最长区间的长度

Sample Input

5
1 7 2 11 15
6
100 100 100 100 100 100
3
1 2 3

Sample Output

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 }

 

L1-6 安装网线

Problem Description

副会长熊大佬的寝室要安装一条网线,可是网线的必经之路被一堵墙挡住了,墙有n层砖头,每一层有ki块砖块组成,总宽度固定。
技术分享
墙的俯视图
熊大佬发现,可以从砖头的缝隙中传过去,但不幸的是,熊大佬的网线是高贵的超七类土豪金网线,无法在缝隙中弯折,所以对于无法笔直穿过的砖块只能用电钻钻出一个洞。现在熊大佬想问,为了让网线穿过这堵墙,最少需要钻开多少块钻块(不能从墙的左右边缘穿过,那样答案总是0就不好玩了)。

Input

输入有多组数据,直到文件结尾。
每组数据首行为一个正整数n,表示墙的层数。
之后n行,每行第一个数字ki表示这层的砖块数,之后有ki个正整数表示这层每块砖块的宽度。
砖块总长度不超过INT_MAX/1000。
每块砖块的宽度范围[1,10000],墙的层数范围[1,10000]。
墙的宽度不会超过int范围。
大量输入,请使用scanf。
题目输入保证每层的砖块宽度和是相等的。

Output

每组数据输出一个整数,表示最少需要用电钻钻多少块砖头。

Sample Input

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

Sample Output

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 }

L2-1 N!

Problem Description

输出N的阶乘。(注意时间限制150ms&&注意不能打表后输出,赛后我们会检查代码,如有发现,该位同学总分记0分处理)

打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入所提交的代码。

Input

多组输入到文件结尾
每组输入一个整数n,(0<=n<=23)。

Output

每组测试数据输出一行,为n!。

Sample Input

1
2

Sample Output

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!