Contest2815

阅读: 评论:0

Contest2815

Contest2815

题L和M见=%257B%2522request%255Fid%2522%253A%2522162125264216780264019610%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=162125264216780264019610&biz_id=0&utm_medium=distribute.pc_-task-blog-2~all~first_rank_v2~rank_v29-3-116834673.pc_search_result_cache&utm_term=%E4%B8%80%E7%AE%AD%E5%A4%9A%E9%9B%95&spm=1018.2226.3001.4187

问题 A: No Problem!

题目描述

Programming contests are being arranged so frequently these days. While this might be a good news for the contestants, the scenario is completely opposite for the problemsetters. So far, the problemsetters somehow managed to produce some sorts of a set & say “No problem!”. But it is doubtful how long will it be possible if the trend of arranging contests in a short notice continues.
You are given the number of problems created in every month of a year and number of problems required in each month. If N problems are required in a month & there are not enough problems at that time, all contests of that month is canceled. Write a program to determine if there are enough problems for the contests. Please keep in mind that, if a problem is created in month X, it can only be used in month X + 1 & the later months.

输入

The first line of every test case has an integer S (0 ≤ S ≤ 100). Number of problems that is ready at the beginning of the year. The 2-nd line has 12 space separated integers, denoting the number of problems created in each of the 12 months of that year. The months are in the same order as they appear in a year. The 3-rd line has another 12 space separated integers, the number of problems required to use in contests in those 12 months (With the same order as above). These integers will be between 0 & 20 (inclusive). The end of input will be denoted by a negative integer.

输出

For each test case, print a line of the form, ‘Case X:’, where X is the case number. Then print 12 lines.
If there are enough problems to meet the requirements in month i (1 ≤ i ≤ 12), print ‘No problem!
:D’ in the i-th line, otherwise print ‘No problem. :(’

样例输入 

5
3 0 3 5 8 2 1 0 3 5 6 9
0 0 10 2 6 4 1 0 1 1 2 2
-1

样例输出 

Case 1:
No problem! :D
No problem! :D
No problem. :(
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D

思路:

看已有题数能否满足需出题数,若能,输出No problem! :D,若不能输出No problem. :(        (注意当输入为-1时退出循环,判断条件为s<0而不是s==-1)

#include<iostream>
using namespace std;
typedef long long ll;
int a[12],b[12],t[12];
int main()
{int s,m=1,cnt=12;while(cin>>s){ll sum=0;if(s<0) break;for(int i=0;i<cnt;i++)cin>>a[i];for(int i=0;i<cnt;i++)cin>>b[i];for(int i=0;i<cnt;i++) t[i]=0;t[0]=s;for(int i=1;i<cnt;i++){t[i]+=t[i-1]+a[i-1];}printf("Case %d:n",m++);for(int i=0;i<cnt;i++){t[i]-=sum;if(t[i]>=b[i]){printf("No problem! :Dn");sum+=b[i];}else{printf("No problem. :(n");}}}return 0;
}

问题 B: Brother Arif, please feed us!

题目描述

Brother Arif is a great problemsetter. He loves grid. Also, he loves light. That’s why the other problemsetters believe that asking him to throw a feast is always right. Unfortunately Brother Arif himself doesn’t think so. Instead of all the naggings and reasons going on around him, he stays in his chair with dreamy eyes and lovingly thinks about newer ways of placing lights inside a 2D grid. Now,it’s time to make your stand for the deprived problemsetters’ right and force Brother Arif to their pleas. 
Now, the problemsetters have all gathered inside a room. The fl oor of this room is shaped like a 2d Rectangular grid consisting of many cells. Any of the problemsetters can stand on a cell. A cell has
enough place for only one people and everyone must occupy exactly one cell at a time. Brother Arif,standing on one of these cells, can move to one of the four adjacent cells just once or he may not move at all. He may not leave the grid, however. The other problemsetters are standing on other cells. With the help of their new telecatching device, they can capture anyone standing at the same row or column irrespective to his distance. So, now you are given the positions of the problemsetters and are asked to figure out if Brother Arif can escape from getting captured (and thus throwing a huge party.)

输入

The input file has multiple test cases. Each test case begins with 3 integers, R (1 ≤ R ≤ 10000), C(1 ≤ C ≤ 10000) & N (1 ≤ Ne2000). R & C are the number of rows & columns in the grid while N denotes the number of problemsetters present on the room. N + 1 lines follow the first line. Each of the next N lines has 2 integers, r (0 ≤ r < R) & c (0 ≤ c < C), position of a problemsetter. For your reference, the upper left corner of the cell has (0, 0) while the lower left one has (R − 1, 0) and the lower right one has (R − 1, C − 1) co-ordinate. The last line gives the co-ordinate of Brother Arif in the same format. The last test case will be followed by a case with R = C = N = 0. This case should not be processed.

输出

For each test case, print a line. This line starts like, ‘Case X: ’, where, X is the case number. After that print a string based on Brother Arif’s destiny. If Brother Arif can find a cell where none else can catch him, print ‘Escaped again! More 2D grid problems!’. If someone can capture him no matter in which cell he goes, print ‘Party time! Let's find a restaurant!’

样例输入 

5 5 2
0 1
4 2
1 2
5 5 3
0 1
4 2
4 3
1 2
0 0 0

样例输出 

Case 1: Escaped again! More 2D grid problems!
Case 2: Party time! Let's find a restaurant!

思路:五种移动方式,上,下,左,右,原地不动。判断能否通过移动使得在同一列或者同一行上

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,l,n,m=0;
int row[100005],col[100005];//行,列
int isescape(int x,int y)
{if(y+1<=l&&row[x]==0&&col[y+1]==0) return 1;//上 if(row[x]==0&&col[y]==0) return 1;//不动 if(y-1>=0&&row[x]==0&&col[y-1]==0) return 1;//下 if(x+1<=h&&row[x+1]==0&&col[y]==0) return 1;//右 if(x-1>=0&&row[x-1]==0&&col[y]==0) return 1;//左 return 0;
}
int main()
{while(cin>>h>>l>>n){int a,b,x,y;m++;memset(row,0,sizeof row);memset(col,0,sizeof col);if(h==l&&l==n&&n==0) break;for(int i=0;i<n;i++){cin>>a>>b;row[a]=1;col[b]=1;}cin>>x>>y;printf("Case %d: ",m);if(isescape(x,y)==1) printf("Escaped again! More 2D grid problems!n");else printf("Party time! Let's find a restaurant!n");}return 0;
} 

问题 C: Pole Position

题目描述

In car races, there is always a high pole next to the finish line of the track. Before the race starts, the pole is used to display the starting grid. The number of the first car in the grid is displayed at the top of the pole, the number of the car in second place is shown below that, and so on.
During the race, the pole is used to display the current position of each car: the car that is winning the race has its number displayed at the top of the pole, followed by the car that is in second place, and so on.
Besides showing the current position of a car, the pole is also used to display the number of positions the cars have won or lost,relative to the starting grid. This is done by showing, side by side to the car number, an integer number. A positive value v beside a car number in the pole means that car has won v positions relative to the starting grid. A negative value v means that car has lost v positions relative to the starting grid. A zero beside a car number in the pole means the car has neither won nor lost any positions relative to the starting grid (the car is in the same position it started).
We are in the middle of the Swedish Grand Prix, the last race of the World Championship. The race director, Dr. Shoo Makra, is getting worried: there have been some complaints that the software that controls the pole position system is defective, showing information that does not refl ect the true race order. 
Dr. Shoo Makra devised a way to check whether the pole system is working properly. Given the information currently displayed in the pole, he wants to reconstruct the starting grid of the race. If it is possible to reconstruct a valid starting grid, he plans to check it against the real starting grid. On the other hand, if it is not possible to reconstruct a valid starting grid, the pole system is indeed defective.
Can you help Dr. Shoo Makra?

输入

The input contains several test cases. The first line of a test case contains one integer N indicating the number of cars in the race (2 ≤ N ≤ 103). Each of the next N lines contains two integers C and
P, separated by one space, representing respectively a car number (1 ≤ C ≤ 104) and the number of positions that car has won or lost relative to the starting grid ( −106 ≤ P ≤ 106), according to the pole system. All cars in a race have diff erent numbers.
The end of input is indicated by a line containing only one zero.

输出

For each test case in the input, your program must print a single line, containing the reconstructed starting grid, with car numbers separated by single spaces. If it is not possible to reconstruct a valid starting grid, the line must contain only the value -1.

样例输入 

4
1 0
3 1
2 -1
4 0
4
22 1
9 1
13 0
21 -2
3
19 1
9 -345
17 0
7
2 2
8 0
5 -2
7 1
1 1
9 1
3 -3
0

样例输出 

1 2 3 4
-1
-1
5 8 2 3 7 1 9

思路:有多个样例输入,每个样例表示n辆汽车行驶,给出目前各车位次及其较初始位次改变为此(负数表示名次往后),求各车最初始的位次。

#include<iostream>
#include<cstring>
using namespace std;
int main()
{int n,a[100005],b[100005],c[100005];//数组a,b表示各车目前位次以及较最初位次改变的位次,数组c作判断用while(cin>>n&&n){bool flag=true;memset(c,0,sizeof c);for(int i=1;i<=n;i++){cin>>a[i]>>b[i];if(b[i]+i<1||b[i]+i>n) {flag=false;continue;}if(c[b[i]+i]) flag=false;else c[b[i]+i]=a[i];}if(!flag) cout<<-1;elsefor(int i=1;i<=n;i++){cout<<c[i]<<" ";}cout<<endl;}return 0;
} 

问题 D: Perfect Choir

题目描述

The Conductor of the choir is planning to take part in the famous Brazilian Choir Week, and therefore she wants the choir to rehearse a new song, described as follows:
• each member of the choir starts singing one note, and only changes the note when determined by the Conductor;
• at the end of each bar measure, the Conductor determines that exactly two singers change the note they are singing: one singer starts to sing the note immediately above the note she sang,and another singer starts to sing the note immediately below the note she sang;
• the song finishes at the end of the first bar measure in which all singers are singing the same note.
The Conductor already has several ideas of how to distribute the notes among choir members at the beginning of the song, in order to create the desired eff ect. However, she is worried about whether,
given a note distribution for the singers, it is possible to reach the end of the song in the way she wants (all singing the same note). And, if that is possible, she wants to know the minimum number of bar measures the song can have. Can you help her?

输入

The input contains several test cases. The first line of a test case contains an integer N indicating the number of members of the choir. Notes are indicated by integers. The second line contains N integers, indicating the note that each singer must sing at the beginning of the song. Notes are given in non-decreasing order.

输出

For each test case, print a line containing a single integer indicating the minimum number of bar measures the song can have. If it is not possible to have all members singing the same note, then print
the value ‘-1’.
Restrictions
• 2 ≤ N ≤ 
• − ≤ notei ≤  for 0 ≤ i ≤ N − 1
• notei ≤ notei+1 for 0 ≤ i ≤ N − 2

样例输入 

3
1 2 3
4
3 6 9 12
6
1 2 3 4 5 723
5
10 10 10 10 10

样例输出 

2
-1
601
1

思路:

判断输入的数总和sum能否整除n,若不能则无法调节音符使得满足条件,输出-1,若能则找到输入的数的平均值求每个数与平均值之差的绝对值的和

#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int MAXN=0x7f7f7f7f;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
int main()
{ll sum=0,s=0,n,a[100005];while(cin>>n){s=0,sum=0;for(ll i=0;i<n;i++){cin>>a[i];sum+=a[i];}for(ll i=0;i<n;i++)s+=abs(sum/n-a[i]);if(sum%n){cout<<-1<<endl;continue;}elsecout<<s/2+1<<endl;}
}

问题 E: Memory Overflow

题目描述

The Great Sultan Mahbub is having some serious issues with his memory. His busy days filled with great works and surrounded by even greater people have brought him to a situation where he has become quite forgetful. For example, he often forgets trivial things like the size of his suit, his weight,small grammatical issues related to gender & number, the address of his in-laws house, how to ride a cycle, deadlines, the day of the week, the name of the guy who forgot his wedding day and even the date of his own wedding (thus spending the day writing alternate solutions to ICPC problems). But when his father-in-law captured him to his in-laws house and he failed to recognize his mother-in-law it became a fiasco. And after some rather presumable events following that debacle, the detail of which does not seem really safe to mention, he decided that the matter has become pressing enough for his attention. His physician is startled by this weird problem and decides to collect statistical data to begin with.
During the examination period consisting n consecutive days, the Sultan meets a single person everyday. He only recognizes the person if he has met him in the last k days (excluding today of course). You need to count the number of days (among these n days) he manages to recognize the people he meets. You can assume that before these n consecutive days he did not meet any person.

输入

The input begins with a number t (1 ≤ t ≤ 100), the number of test cases. Each of the following lines contains a case. A case begins with n (1 ≤ n ≤ 500) & k (1 ≤ k ≤ 500). A list of n names follows. All
names consist of a single uppercase letter and names are unique. They are given in the order of which Sultan meets them during the investigation. There won’t be any invalid character or space between
any two names.

输出

For each test case produce a line of the form ‘Case X: Y ’. X is the serial number of the test case while Y is the number of people Sultan recognizes.
Illustration of Third sample:
Day 1: Sultan remembers nobody, meets ’M’. Does not recognize.
Day 2: Remembers only ’M’ but meets ’A’. Does not recognize again.
Day 3: Now remembers ’M’ & ’A’. Meets ’H’. Recognition count remains 0.
Day 4: Forgets ’M’, remembers ’A’ & ’H’. Meets ’B’. Still nothing happens.
Day 5: Forgets ’A’, remembers ’H’ & ’B’. Meets ’U’. No luck yet.
Day 6: Forgets ’H’, remembers ’B’ & ’U’. Meets ’B’ again and recognizes this time making the recognition count 1.

样例输入 

3
6 2 SULTAN
6 1 MAHBUB
6 2 MAHBUB

样例输出 

Case 1: 0
Case 2: 0
Case 3: 1

思路:

一个人只能记住n天之中前k天见到的人,用大写字母表示,求他能记住的人的个数。

#include<bits/stdc++.h>
using namespace std;
int a[2000],b[2000];
string s;
int main()
{int n,k,t,sum,first,last,m=1;cin>>t;while(t--){cin>>n>>k>>s;first=1,sum=0;last=0;memset(b,0,sizeof(b));for(int i=0;s[i];i++){if(b[int(s[i])]!=0) sum++;a[++last]=int(s[i]);if(last+1-first>k)b[a[first++]]=0;for(int j=first;j<=last;j++) b[a[j]]=1;}printf("Case %d: %dn",m++,sum);}return 0;
}

问题 F: Strategy Game

题目描述

A strategy game with J players is played around a table. Players are identified by numbers from 1 to J and will play a total of R rounds.
At each round each player will play once, in the order of their identifiers; that is, player 1 will play first, player 2 will play second, and so on. Once player J plays, the round is complete, and a next round starts.
A player earns a certain amount of Victory Points every time she or he plays. After all rounds are finished the total points of each player is computed as the sum of Victory Points the player earned on
each round. The winner is the player with the maximum number of points; in case of a tie the winner is the player who earned the maximum number of points and played last.
Given the number of players, the number of rounds and a list describing the Victory Points in the order they were obtained, you must determine which player is the winner.

输入

The input contains several test cases. In each test case, the first line contains two integers J and R,respectively the number of players and the number turns (1 ≤ J, R ≤ 500). The second line contains
J ∗ R integers, representing the Victory Points earned by each player in each turn, in the order they happened. The Victory Points obtained in each turn will be always integer numbers between 0 and 100, inclusive.

输出

For each test case in the input, your program must produce one single line, containing the integer representing the winner.

样例输入 

3 3
1 1 1 1 2 2 2 3 3
2 3
0 0 1 0 2 0

样例输出 

3
1

思路:

n个人编号1-n,两两下棋,求得分最高的人的编号

#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const int MAXN=0x7f7f7f7f;
const int INF=0x3f3f3f3f;
int main()
{int j,r;while(cin>>j>>r){int q[j],m,p[j];memset(q,0,sizeof(q));for(int i=0;i<j*(r-1);i++){cin>>m;q[i%j]+=m;}for(int i=0;i<j;i++){cin>>p[i];q[i]+=p[i];}int max1=0,k;bool flag;for(int i=0;i<j;i++){if(max1<q[i]) {max1=q[i];}
}
for(int i=0;i<j;i++)
{if(max1==q[i]){k=i+1;flag=true;
}elsep[i]=0;
}if(flag==true) cout<<k;else{int max2=0;for(int i=0;i<j;i++)if(max2<p[i]) max2=p[i];for(int i=j-1;i>=0;i--){if(max2==p[i]){cout<<i+1;break;}}}cout<<endl;}return 0;}

问题 G: Cacho

题目描述

In Bolivia there is a very popular game called “Cacho”. The game consists rolling five dices( a1 , a2 , a3 ,a4 , a5 ) and then annotate the result according to certain rules. This time we will focus on one case in particular: “escala”. A “escala” is the scene in which the dices form a sequence of consecutive numbers.
More formally a “escala” meets the property:
ai + 1 = ai+1, 1 ≤ i ≤ 4
There are two types of “escala”: a ordinary “escala” (it satisfy the property described above), and a “Escala Real” (when the scenery is 1, 3, 4, 5, 6. In the game this case is also a valid “scala”).
Cael is a boy who is learning to play and wants you to help develop a program to check when five dices are forming a “escala”. Note that the “Escala Real” is not a valid “escala” for Cael.

输入

The input begins with a number T ≤ 100, the number of test cases. Below are T lines, each with five numbers ai (1 ≤ ai ≤ 6) in no-decreasing order.

输出

In each case, if the five dices form a scale print in one line‘ Y’. Otherwise print in one line ‘N’ (quotes for clarity).

样例输入 

5
1 2 3 4 5
2 3 4 5 6
1 4 4 4 5
1 3 4 5 6
1 2 2 3 6

样例输出 

Y
Y
N
N
N

思路

输入n行,每行n个数,若能满足 + 1 = ,输出Y,否则输出N

#include<bits/stdc++.h>
using namespace std;
int main()
{int t,a[10],flag=0;cin>>t;while(t--){for(int i=0;i<5;i++)cin>>a[i];flag=0;for(int i=0;i<4;i++){if(a[i]+1!=a[i+1]){flag=0;break;}elseflag=1; }if(flag)cout<<"Y"<<endl;elsecout<<"N"<<endl;}return 0; } 

问题 J: 超市收银

题目描述

小明在一家超市做兼职收银员。恰好在昨天,他使用的电脑突然死机,重启后发现几天的账目都被清空了,在全力恢复数据后,总算找回了所有的每笔交易收入和找零的数据。例如,某笔交易收银机显示应收67元,实收100元,找零33元,这里能恢复的数据就只有100和33。
由于交易数量太多,小明忙了一整天还没有完成,请你帮他写一个程序计算一下所有数据的总收入吧!

输入

第一行输入一个n,表示恢复出来的交易数目。
接下来n行,每行两个整数,表示每笔交易的实收和找零数据。恢复出的数据,不保证实收是前一个数,可以确定的是:实收值肯定不小于找零的值。

输出

输出一个整数,表示n笔交易的收入总值。

样例输入 

【样例1】
3
100 20
20 4
41 5
【样例2】
2
10 0
22 5

样例输出 

【样例1】
132
【样例2】
27

思路:

重点在前一个数不一定比后一个数大,加个绝对值就行。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{int n;cin>>n;ll s=0,a,b;while(n--){cin>>a>>b;s+=abs(a-b);
}cout<<s<<endl;return 0;
}

问题 K: 足球联赛

题目描述

小明热爱足球,也热爱家乡球队1队。新的一年足球联赛又开始了,共n个球队,进行双循环比赛。双循环比赛是指每个球队与其他n-1只队伍分别踢两场正式比赛,就是主场和客场比赛。如下图,在n=3的情况下,表示3只球队,共6场比赛。

第i行有n-1场比赛,表示球队i所踢的n-1场主场比赛。第i列就是队i的n-1场客场比赛。上表中第一行表示队1在主场4:3战胜了队2,在与队3的对比赛中1:2不敌对手;而客场比赛与队2战成0:0平,又以2:1战胜了队3。
根据足球联赛的得分规则,以双方进球多少评判比赛胜负,比赛战平(进球数一样多),双方各得1分;如果比赛分出胜负,那么获胜方(进球多的)得到3分,输的那方不得分。
队1在主场一胜一负,得到3分,在客场一胜一平,得到4分。队1的总积分为7分。
队2在主场一胜一平,得到4分,在客场一平一负,得到1分,队2的总积分为5分。
队3总得分为4分
因此,队1分数最高,可以获得冠军。联赛规定,若有多个得分最高的队伍,他们将分享冠军的荣誉,同时获得冠军。
现在小明想要知道,在看完并记录下所有比赛后,家乡球队队1能否获得冠军,并计算出队1赛季总积分。

输入

第一行一个整数n,表示参加联赛的球队数量,小明支持的就是队1。
接下来n行,每行n*2个整数,第i行第j对整数表示队i在主场对阵队j的比赛情况,两个整数分别表示主队(队i)和客队(队j)的进球数。当i=j的时候,两个整数用-1表示,自己和自己踢球的情况是不存在的。

输出

若队1夺冠,那么在第一行输出“Yes”;若1队的总积分不是最高的,那么在第一行输出“No”。
第二行输出一个整数,表示队1的赛季总积分。

样例输入 

【样例1】
3
-1 -1 4 3 1 2
0 0 -1 -1 3 0
1 2 1 1 -1 -1
【样例2】
2
-1 -1 2 2
3 0 -1 -1

样例输出 

【样例1】
Yes
7
【样例2】
No
1

提示

样例2解释
共2个球队,踢2场比赛,第一场队1在主场和队2打成平手,第二场队2在主场3:0战胜队1。队1一平一负积1分,队2一胜一平得4分。队1没有夺冠,积分为1分。

【数据范围】
100%的数据,n<=30,每个球队的进球数量不超过10。
评分标准,输出是否夺冠正确将得到该测试点一半的分数;总积分输出正确,将得到该测试点另一半分数。

思路:

利用二维数组表示每场比赛每队得分,根据题意判断即可

#include<bits/stdc++.h>
using namespace std;
int n;
int b[35][35],c[35][35];
struct Node
{int sum;
}a[35];
int main()
{cin>>n;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){cin>>b[i][j]>>c[i][j];
}memset(a,0,sizeof(a));for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){	if(b[i][j]==c[i][j]&&b[i][j]==-1)continue;if(b[i][j]>c[i][j])  a[i].sum+=3;if(b[i][j]==c[i][j]&&b[i][j]!=-1)  {a[i].sum++;	a[j].sum++;}if(b[i][j]<c[i][j])  a[j].sum+=3;}
}
}int k=a[1].sum;int flag=0;for(int i=1;i<=n;i++){if(k<a[i].sum){flag=1;break;
}
}
if(flag)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
cout<<k<<endl;return 0;
}

 

本文发布于:2024-02-04 17:46:49,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170712916057958.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23