AtCoder Beginner Contest 085(ABCD)
A - Already 2018
题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd
format. For example, January 23, 2018 should be written as 2018/01/23
.
After finishing the document, she noticed that she had mistakenly wrote 2017
at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018
and prints it.
Constraints
- S is a string of length 10.
- The first eight characters in S are
2017/01/
. - The last two characters in S are digits and represent an integer between 1 and 31 (inclusive).
Input
Input is given from Standard Input in the following format:
S
Output
Replace the first four characters in S with 2018
and print it.
Sample Input 1
2017/01/07
Sample Output 1
2018/01/07
Sample Input 2
2017/01/31
Sample Output 2
2018/01/31
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 string s; 6 while(cin>>s){ 7 int l=s.length(); 8 for(int i=0;i<l;i++){ 9 if(i==0) cout<<'2'; 10 else if(i==1) cout<<'0'; 11 else if(i==2) cout<<'1'; 12 else if(i==3) cout<<'8'; 13 else cout<<s[i]; 14 } 15 cout<<endl; 16 } 17 return 0; 18 }
B - Kagami Mochi
题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_b
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
An X-layered kagami mochi (X≥1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.
Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is di centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
Constraints
- 1≤N≤100
- 1≤di≤100
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N d1 : dN
Output
Print the maximum number of layers in a kagami mochi that can be made.
Sample Input 1
4 10 8 8 6
Sample Output 1
3
If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.
Sample Input 2
3 15 15 15
Sample Output 2
1
When all the mochi have the same diameter, we can only have a 1-layered kagami mochi.
Sample Input 3
7 50 30 50 100 50 80 30
Sample Output 3
4
题解:计算一堆数里最大不重复的个数
1 #include <iostream> 2 #include <set> 3 using namespace std; 4 int main() 5 { 6 int n; 7 set<int> s; 8 while(cin>>n){ 9 s.clear(); 10 while(n--){ 11 int x; 12 cin>>x; 13 s.insert(x); 14 } 15 int sum=s.size(); 16 cout<<sum<<endl; 17 } 18 return 0; 19 }
C - Otoshidama
题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_c
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.
According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
Constraints
- 1≤N≤2000
- 1000≤Y≤2×107
- N is an integer.
- Y is a multiple of 1000.
Input
Input is given from Standard Input in the following format:
N Y
Output
If the total value of N bills cannot be Y yen, print -1 -1 -1
.
If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.
Sample Input 1
9 45000
Sample Output 1
4 0 5
If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0
is also correct.
Sample Input 2
20 196000
Sample Output 2
-1 -1 -1
When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.
Sample Input 3
1000 1234000
Sample Output 3
14 27 959
There are also many other possibilities.
Sample Input 4
2000 20000000
Sample Output 4
2000 0 0
题解:与找零钱类似
#include <iostream> #include <set> using namespace std; int main() { int n,Y; while(cin>>n>>Y){ Y/=1000; if(n*10<Y||n>Y){ cout<<-1<<" "<<-1<<" "<<-1<<endl; continue; } int flag=0; for(int i=n;i>=0;i--){ for(int j=n-i;j>=0;j--){ for(int l=n-i-j;l>=0;l--){ if((i+j+l==n)&&(i*10+j*5+l==Y)){ cout<<i<<" "<<j<<" "<<l<<endl; flag=1; break; } } if(flag) break; } if(flag) break; } if(!flag) cout<<-1<<" "<<-1<<" "<<-1<<endl; } return 0; }
D - Katana Thrower
题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_d
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:
- Wield one of the katana you have. When you wield Katana i (1≤i≤N), the monster receives ai points of damage. The same katana can be wielded any number of times.
- Throw one of the katana you have. When you throw Katana i (1≤i≤N) at the monster, it receives bi points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.
The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
Constraints
- 1≤N≤105
- 1≤H≤109
- 1≤ai≤bi≤109
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N H a1 b1 : aN bN
Output
Print the minimum total number of attacks required to vanish the monster.
Sample Input 1
1 10 3 5
Sample Output 1
3
You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3+3+5=11 points of damage in a total of three attacks, vanishing the monster.
Sample Input 2
2 10 3 5 2 6
Sample Output 2
2
In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5+6=11 points of damage in two attacks, vanishing the monster.
Sample Input 3
4 1000000000 1 1 1 10000000 1 30000000 1 99999999
Sample Output 3
860000004
Sample Input 4
5 500 35 44 28 83 46 62 31 79 40 43
Sample Output 4
9
题解:找出a中最大的maxn 然后依次扔出b中比a大的 如果还有多 全用a中最大的maxn
1 #include<bits/stdc++.h> 2 using namespace std; 3 long long a[100005],b[100005]; 4 bool cmp(int x,int y) 5 { 6 return x>y; 7 } 8 int main() 9 { 10 long long n,h; 11 while(cin>>n>>h){ 12 for(int i=0;i<n;i++){ 13 cin>>a[i]>>b[i]; 14 } 15 sort(a,a+n,cmp); 16 long long maxn=a[0],s=0; 17 sort(b,b+n,cmp); 18 for(int i=0;i<n;i++){ 19 if(b[i]>=maxn&&h>=maxn){ 20 h-=b[i]; 21 s++; 22 } 23 } 24 if(h>=0){ 25 s+=h/maxn; 26 if(h%maxn!=0) s++; 27 } 28 29 cout<<s<<endl; 30 } 31 return 0; 32 }