Alice and Bob are decorating a Christmas Tree.
Alice wants only r red ornaments.
In Bob's opinion, a Christmas Tree will be beautiful if:
- the number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and
- the number of red ornaments used is greater by exactly 1 than the number of blue ornaments.
That is, if they have 6=5+1).
Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.
In the example two paragraphs above, we would choose 7+8+9=24ornaments. That is the maximum number.
Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree!
It is guaranteed that it is possible to choose at least 1+2+3=6) ornaments.
The only line contains three integers 3≤r≤100) — the number of yellow, blue and red ornaments.
It is guaranteed that it is possible to choose at least 1+2+3=6) ornaments.
Print one number — the maximum number of ornaments that can be used.
8 13 9
24
13 3 6
9
In the first example, the answer is 7+8+9=24.
In the second example, the answer is 2+3+4=9.
我的代码:
#include <iostream> using namespace std; int main() { int y,b,r; while(cin>>y>>b>>r){ for(int i=r;i>=3;i--){ if(b>=(i-1)&&y>=(i-2)){ cout<<i+i-1+i-2<<endl; break; } } } return 0; }
大佬的代码:
/** * author: tourist * created: 30.12.2018 17:35:22 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> a >> b >> c; int x = min(b, min(a + 1, c - 1)); cout << 3 * x << '\n'; return 0; }
Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out.
Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at home. Since he does not know which clue belongs to which obelisk, finding the treasure might pose a challenge. Can you help him?
As everyone knows, the world is a two-dimensional plane. The T is the same for all clues.
In other words, each clue belongs to exactly one of the obelisks, and each obelisk has exactly one clue that belongs to it. A clue represents the vector from the obelisk to the treasure. The clues must be distributed among the obelisks in such a way that they all point to the same position of the treasure.
Your task is to find the coordinates of the treasure. If there are multiple solutions, you may print any of them.
Note that you don't need to find the permutation. Permutations are used only in order to explain the problem.
The first line contains an integer 1≤n≤1000) — the number of obelisks, that is also equal to the number of clues.
Each of the next i≠j.
Each of the next i≠j.
It is guaranteed that there exists a permutation (xpi+ai,ypi+bi)=(xpj+aj,ypj+bj).
Output a single line containing two integers Tx,Ty — the coordinates of the treasure.
If there are multiple answers, you may print any of them.
2 2 5 -6 4 7 -2 -1 -3
1 2
4 2 2 8 2 -7 0 -2 6 1 -14 16 -12 11 -18 7 -14
9 -12
As n=2, we can consider all permutations on two elements.
If (−7,1). However, both obelisks must give the same location, hence this is clearly not the correct permutation.
If the hidden permutation is T=(1,2) is the location of the treasure.
In the second sample, the hidden permutation is [2,3,4,1].
我的代码,当然没通过了...在第33组数据超时了.
#include <iostream> #include <map> #include <string> #include <sstream> #include <cstdio> using namespace std; map<string,int> m1; int obe[1005][2]; int main() { int n,x,y,a,b; int resx,resy; cin>>n; for(int i=0;i<n;i++){ cin>>obe[i][0]>>obe[i][1]; } int t1,t2;std::stringstream ss; for(int i=0;i<n;i++){ //scanf("%d %d",&t1,&t2); cin>>t1>>t2; int newx,newy; for(int j=0;j<n;j++){ newx=obe[j][0]+t1; newy=obe[j][1]+t2; string tmp1,tmp2; ss.clear(); ss<<newx; ss>>tmp1; ss.clear(); ss<<newy; ss>>tmp2; tmp1=tmp1+","; tmp1=tmp1+tmp2; //cout<<tmp1; m1[tmp1]++; } } map<string,int>::iterator aa=m1.begin(); for(;aa!=m1.end();aa++){ if(aa->second==n){ string tmp=aa->first; int i; for(i=0;tmp[i]!=',';i++){ cout<<tmp[i]; } printf(" "); for(i++;i<tmp.size();i++){ //printf("%c",tmp[i]); cout<<tmp[i]; } cout<<endl; break; } } return 0; }
还是看一下tourist的吧.
题意是n个起点,有n个向量,有个一一对应的关系使每个起点加上一个向量之后是同一个点,让输出那个点的坐标.
所以这些每个起点+向量都是得到相同的坐标,然后把这每个值再加起来就是坐标的n倍啊!
再就是我的基本操作都不会啊,连个int和string 的相互转换都不会...
/** * author: tourist * created: 30.12.2018 17:36:58 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long long x = 0, y = 0; for (int i = 0; i < 2 * n; i++) { int xx, yy; cin >> xx >> yy; x += xx; y += yy; } cout << (x / n) << " " << (y / n) << '\n'; return 0; }
拖哥的代码中有两句看不懂的:
ios::sync_with_stdio(false);
cin.tie(0);
https://www.byvoid.com/zhs/blog/fast-readfile.
(我的代码方法太挫了,加上这个仍然超时...)