问题 D: Eeny Meeny
时间限制: 2 Sec 内存 限制: 128 MB
题目描述
“Eeny meeny miny moe” is a well-known nursery rhyme in English, used (among other things) by kids to “randomly” select members of a team. It exists in many variations, one of which goes like this:
Eeny, meeny, miny, moe,
Catch a tiger by the toe.
If he hollers, let him go,
Eeny, meeny, miny, moe.
Similar verses exist in most languages, such as “Ulle dulle dof” in finnish, “Akka bakka bonka rakka” in Norwegian, and “Ole dole doff” in Swedish.
Two teams are to be selected for a game and the rhyme is used to select one kid for a team at a time, alternating between the two teams, until all kids have been selected. The kids are standing in a circle. In each selection round we start counting the kids in clockwise order around the circle, skipping one kid for every word in the rhyme, until the last word. The kid matching the last word is chosen for the current team and then the next round starts. In all rounds but the first, the counting starts at the next remaining kid (in clockwise order) after the one that was selected in the previous round. See figure E.1 for an example.
Given such a rhyme, and a group of kids, can you tell which kids will be in which team?
figure E.1: Illustration of the first three rounds of Sample Input 1. In rounds 1 and 3, Alvar and Rakel get selected for the first team, and in round 2, Lisa is selected for the second team. In round 4 (not shown), only Kalle remains and is selected for the second team.
输入
The first line of input contains the rhyme, consisting of a list of words separated by spaces. The second line of input contains an integer n (1 ≤ n ≤ 100), the number of kids. Then follow the names of the kids, one per line. The kids are given in clockwise order and the first kid listed is the one at which counting starts in the first round.
All words and names consist only of upper and lower case letters ‘ A ’-‘ Z ’ and ‘ a ’-‘ z ’. No input line is empty or longer than 100 characters (excluding the newline character at the end of the line).
输出
Output the two teams, starting with the one whose first member is chosen first. For each team, output the number of kids in the team, followed by the names of the kids in the team, in the same order as they were chosen for the team.
样例输入 Copy
eeny meeny miny 4 Kalle Lisa Alvar Rakel
样例输出 Copy
2 Alvar Rakel 2 Lisa Kalle
题目大意
大意可以理解为:有n个人,开始的时候,第一个人开始数数,数到m,就加入一组队伍,如果是第奇数个加入队伍的,就进入一号队伍,否则就是二号队伍
一直重复这种情况,直到所有人都加入队伍
最后问每个队伍有多少人,分别有谁
经典的约瑟夫环
Main_code:
int n; string in; struct node { string name; int val; int t; }; bool cmp(node a, node b) { if (a.val != b.val) return a.val < b.val; else return a.t < b.t; } node b[maxn]; string a[maxn]; int main() { getline(cin, in); in += '#'; int num = 0; int len = in.size(); cin >> n; for (int i = 1; i <= n; i++) cin >> b[i].name; string temp; for (int i = 0; i < len; i++) { temp += in[i]; if (in[i + 1] == ' ' || in[i + 1] == '#') { a[++num] = temp; temp.clear(); i++; } } int cnt1 = 0, cnt2 = 0; int over = 0; do { ++cnt1; if (cnt1 > n) cnt1 = 1; if (b[cnt1].val == 0) { cnt2++; } if (cnt2 == num) { cnt2 = 0; over++; if (over % 2) b[cnt1].val = 1; else b[cnt1].val = 2; b[cnt1].t = over; } } while (over != n); sort(b + 1, b + 1 + n, cmp); cnt1 = 0; for (int i = 1; i <= n; i++) { if (b[i].val == 1) cnt1 ++; else break; } cout << cnt1 << endl; for (int i = 1; i <= cnt1; i++) { cout << b[i].name << endl; } cout << n - cnt1 << endl; for (int i = cnt1 + 1; i <= n; i++) { cout << b[i].name << endl; } return 0; }
Alphabet Animals
时间限制: 1 Sec 内存限制: 128 MB
题目描述
You are playing a game in which a group of players take turns saying animal names. The animal name you say when it is your turn must start with the same letter as the previously said animal ends with and it must not have been said previously in this round of the game. If there is no valid name or you cannot come up with one you are eliminated.
Given the last animal name said before your turn and a list of all names not yet used, can you make it through this turn? If so, can you make sure to eliminate the next player?
输入
The first line of input contains a single word, the animal that the previous player just said. The next line contains a single integer n (0 ≤ n ≤ 105 ), the number of valid unused animal names.
Each of the following n lines contains one valid unused animal name.
All animal names (including the one the previous player said) are unique and consist of at least 1 and at most 20 lower case letters ‘ a ’-‘ z ’.
输出
If there is any animal name you can play that eliminates the next player, output the first such name from the input list, followed by an exclamation mark.
Otherwise, if there is any animal name that you can play, output the first such name. Otherwise, output a question mark (in this case you will just have to make up a fake name in the hope that the others will trust you that this is a real animal).
样例输入 Copy
pig 2 goat toad
样例输出 Copy
goat
题目分析:
这个题并不难,但是容易被题意卡的死死的
如果能够选出把后面的人卡死的情况下,就输出最优的情况**并且在后面加上一个叹号,否则就输出第一个自己匹配的情况,要是找不到以上两种情况,就输出一个问号**
Main_code:
string s; cin>>s; int lens=s.size(); char ttt = s[lens-1]; int n=read; string ans; for(int i=1;i<=n;i++){ cin>>a[i]; mp[a[i][0]] ++; } int flag=0; for(int i=1;i<=n;i++){ char l=a[i][0]; int lena=a[i].size(); char r=a[i][lena-1]; if((ttt == l && !mp[r])||(ttt==l&&l==r)&&mp[r]==1){ flag=1; ans=a[i]; break; } } if(flag) cout<<ans<<'!'<<endl; else{ for(int i=1;i<=n;i++){ char l=a[i][0]; int lena=a[i].size(); char r=a[i][lena-1]; if(ttt == l){ flag = 1; ans=a[i]; break; } } if(flag) cout<<ans<<endl; else cout<<'?'<<endl; } return 0;
问题 B: Building Boundaries
时间限制: 1 Sec 内存限制: 128 MB
题目描述
Maarja wants to buy a rectangular piece of land and then construct three buildings on that land.
The boundaries of the buildings on the ground must have rectangular sizes a1 × b1 , a2 × b2 ,and a3 × b3 . They can touch each other but they may not overlap. They can also be rotated as long as their sides are horizontal and vertical.
What is the minimum area of land Maarja has to buy?
Figure B.1: Illustration of the two test scenarios in Sample Input 1 and their solutions. In the second scenario the 5 × 1 building has been rotated by 90 degrees.
输入
The input consists of multiple test scenarios. The first line of input contains a single integer t(1 ≤ t ≤ 1000), the number of scenarios. Then follow the t scenarios. Each scenario consists of a single line, containing six integers a1 , b1 , a2 , b2 , a3 and b3 (1 ≤ a1 , b1 , a2 , b2 , a3 , b3 ≤ 109 ).
输出
For each test scenario, output the minimum area of land such that Maarja can construct the three buildings.
样例输入 Copy
2 2 3 2 2 1 1 2 4 5 1 2 3
样例输出 Copy
12 21
题意很简单,给出三个矩形的长和宽,然后找出面积最小的矩形放下这三个矩形,问符合这个条件的矩形的面积是多少
这种问题直接交给队友
队友用的二进制枚举
Main_code:
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N = 1e6 + 10; struct node { ll h, w; }q[6]; ll mi; ll get1(node* q) { //三个一行 ll w = 0, h = 0; for (int i = 1; i <= 3; i++) { w += q[i].w; h = max(h, q[i].h); } return w * h; } ll get2(node* q) { //两个一列 ll w = 0, h = 0; for (int i = 1; i <= 2; i++) { w = max(w, q[i].w); h += q[i].h; } w += q[3].w, h = max(h, q[3].h); return w * h; } ll get3(node* q) { //两个一列 ll w = 0, h = 0; for (int i = 2; i <= 3; i++) { w = max(w, q[i].w); h += q[i].h; } w += q[1].w, h = max(h, q[1].h); return w * h; } ll get4(node* q) { //两个一列 ll w = 0, h = 0; for (int i = 1; i <= 3; i++) { if (i == 2) continue; w = max(w, q[i].w); h += q[i].h; } w += q[2].w, h = max(h, q[2].h); return w * h; } void dfs() { for (ll i = 0; i <= 7; i++) { ll n = i; node tt[6]; for (ll k = 1; k <= 3; k++) { tt[k] = q[k]; } for (ll j = 2; j >= 0; j--) { ll t = (n >> j); if (t & 1) swap(tt[j + 1].h, tt[j + 1].w); } mi = min(mi, get1(tt)); mi = min(mi, get2(tt)); mi = min(mi, get3(tt)); mi = min(mi, get4(tt)); } return; } int main() { int T; cin >> T; while (T--) { for (ll i = 1; i <= 3; i++) { cin >> q[i].w >> q[i].h; } mi = 4e18; dfs(); cout << mi << endl; } return 0; }