Coder-Strike 2014 - Finals (online edition, Div. 2)
2014-04-24 08:31
323 查看
A. Pasha and Hamsters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Pasha has two hamsters: Arthur and Alexander. Pasha put
n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples
between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't
get any apples.
Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.
Input
The first line contains integers n,
a, b
(1 ≤ n ≤ 100; 1 ≤ a, b ≤ n) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains a distinct integers — the numbers of the apples Arthur likes. The next line containsb distinct integers — the numbers of the apples Alexander likes.
Assume that the apples are numbered from 1 to
n. The input is such that the answer exists.
Output
Print n characters, each of them equals either 1 or 2. If thei-h character equals 1, then thei-th apple should be given to Arthur, otherwise
it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
不解释,直接上代码:
B. Start Up
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large
English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word,
determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most105 large English letters. The name will be written with the next sans serif font:
![](http://espresso.codeforces.com/9c6ff312b45700bbea00048ab111fbe5399e5959.png)
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
当时写复杂了。。。 还是菜。
D. Bug in Code
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of then
coders on the meeting said: 'I know for sure that eitherx ory did it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at leastp ofn
coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.
Input
The first line contains integers n and
p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) — the number of coders in the F company and the minimum number of agreed people.
Each of the next n lines contains two integersxi,yi(1 ≤ xi, yi ≤ n)
— the numbers of coders named by thei-th coder. It is guaranteed thatxi ≠ i, yi ≠ i, xi ≠ yi.
Output
Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets(1, 2) and(2, 1) are considered identical.
思路: 统计每个人得到票数,然后排序。 穷举找出所有候选人对,算出他们的支持人数。( 这里需要减去同一人同时支持两个人的情况)。 注意:结果可能超过int范围; 枚举的时候需要优化,不然会超时。
代码:
typedef pair<int, int> mpair;
struct _id{
int id;
int num;
}r[NUM];
map<mpair, int> store;
int n, p;
long long ans;
bool cmp(_id a, _id b)
{
if(a.num != b.num)
return a.num < b.num;
else
return a.id < b.id;
}
void Solution()
{
while(cin >> n >> p)
{
ans = 0;
REPA(i, 1, (n+1))
{
r[i].id = i;
r[i].num = 0;
}
REP(i, n)
{
int a, b;
cin >> a >> b;
(r[a].num) ++;
(r[b].num) ++;
int mn = min(a, b);
int mx = max(a, b);
mpair temp = make_pair(mn, mx);
if( store.find(temp) != store.end())
{
store[temp] ++;
}
else
{
store.insert(make_pair(temp, 1));
}
}
for(map<mpair, int>::iterator it = store.begin(); it != store.end(); it++)
{
mpair temp = it->first;
int value = r[temp.first].num + r[temp.second].num;
if(value >= p && (value - it->second) < p)
ans --;
}
sort(r + 1, r + n + 1, cmp);
int last = -1, value = 0;
REPA(i, 1, n)
{
if(r[i].num != last)
{
REPA(j, (i+1), (n+1)){
if(r[i].num + r[j].num >= p)
{
int temp = n - j + 1;
ans += temp;
last = r[i].num;
if(r[i].num * 2 >= p)
value = temp - 1;
else
value = temp;
break;
}
}
}
else
{
ans += value;
if(r[i].num * 2 >= p)
value --;
}
}
cout << ans << endl;
}
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Pasha has two hamsters: Arthur and Alexander. Pasha put
n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples
between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't
get any apples.
Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.
Input
The first line contains integers n,
a, b
(1 ≤ n ≤ 100; 1 ≤ a, b ≤ n) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains a distinct integers — the numbers of the apples Arthur likes. The next line containsb distinct integers — the numbers of the apples Alexander likes.
Assume that the apples are numbered from 1 to
n. The input is such that the answer exists.
Output
Print n characters, each of them equals either 1 or 2. If thei-h character equals 1, then thei-th apple should be given to Arthur, otherwise
it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
不解释,直接上代码:
void Solution() { while(cin >> n >> a >> b) { CLS(ret, 0); REP(i, a) cin >> a1[i]; REP(i, b) cin >> a2[i]; REP(i, a) { ret[a1[i]] = 1; } REP(i, b) { ret[a2[i]] = 2; } REPA(i, 1, (n+1)) cout << ret[i] << " "; cout << endl; } }
B. Start Up
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large
English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word,
determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most105 large English letters. The name will be written with the next sans serif font:
![](http://espresso.codeforces.com/9c6ff312b45700bbea00048ab111fbe5399e5959.png)
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
当时写复杂了。。。 还是菜。
char in[NUM]; int len; bool is_ok(char c) { char temp[] = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}; REP(i, 11) { if(c == temp[i]) return true; } return false; } void Solution() { while(gets(in)!=NULL) { bool f = true; len = strlen(in); REP(i, len) { if(!is_ok(in[i])) { f = false; break; } } if(f){ REP(i, (len/2)) { if(in[i] != in[len-1-i]) { f = false; break; } } } if(f) puts("YES"); else puts("NO"); // getchar(); } }
D. Bug in Code
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of then
coders on the meeting said: 'I know for sure that eitherx ory did it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at leastp ofn
coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.
Input
The first line contains integers n and
p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) — the number of coders in the F company and the minimum number of agreed people.
Each of the next n lines contains two integersxi,yi(1 ≤ xi, yi ≤ n)
— the numbers of coders named by thei-th coder. It is guaranteed thatxi ≠ i, yi ≠ i, xi ≠ yi.
Output
Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets(1, 2) and(2, 1) are considered identical.
思路: 统计每个人得到票数,然后排序。 穷举找出所有候选人对,算出他们的支持人数。( 这里需要减去同一人同时支持两个人的情况)。 注意:结果可能超过int范围; 枚举的时候需要优化,不然会超时。
代码:
typedef pair<int, int> mpair;
struct _id{
int id;
int num;
}r[NUM];
map<mpair, int> store;
int n, p;
long long ans;
bool cmp(_id a, _id b)
{
if(a.num != b.num)
return a.num < b.num;
else
return a.id < b.id;
}
void Solution()
{
while(cin >> n >> p)
{
ans = 0;
REPA(i, 1, (n+1))
{
r[i].id = i;
r[i].num = 0;
}
REP(i, n)
{
int a, b;
cin >> a >> b;
(r[a].num) ++;
(r[b].num) ++;
int mn = min(a, b);
int mx = max(a, b);
mpair temp = make_pair(mn, mx);
if( store.find(temp) != store.end())
{
store[temp] ++;
}
else
{
store.insert(make_pair(temp, 1));
}
}
for(map<mpair, int>::iterator it = store.begin(); it != store.end(); it++)
{
mpair temp = it->first;
int value = r[temp.first].num + r[temp.second].num;
if(value >= p && (value - it->second) < p)
ans --;
}
sort(r + 1, r + n + 1, cmp);
int last = -1, value = 0;
REPA(i, 1, n)
{
if(r[i].num != last)
{
REPA(j, (i+1), (n+1)){
if(r[i].num + r[j].num >= p)
{
int temp = n - j + 1;
ans += temp;
last = r[i].num;
if(r[i].num * 2 >= p)
value = temp - 1;
else
value = temp;
break;
}
}
}
else
{
ans += value;
if(r[i].num * 2 >= p)
value --;
}
}
cout << ans << endl;
}
}
相关文章推荐
- Coder-Strike 2014 - Finals (online edition, Div. 2 A、B)
- Coder-Strike 2014 - Finals (online edition, Div. 2) Online Meeting
- Coder-Strike 2014 - Finals (online edition, Div. 2)
- Coder-Strike 2014 - Finals (online edition, Div. 2) Online Meeting
- Codeforces Coder-Strike 2014 - Finals (online edition, Div. 1)
- Coder-Strike 2014 - Finals (online edition, Div. 2) B. Start Up
- Coder-Strike 2014 - Finals (online edition, Div. 2)——Bug in Code
- Coder-Strike 2014 - Finals (online edition, Div. 2) A. Pasha and Hamsters
- Coder-Strike 2014 - Finals (online edition, Div. 1)-a-b-c
- Coder-Strike 2014 - Finals (online edition, Div. 2)AB
- codeforces-Coder-Strike 2014 - Finals (online edition, Div. 2)
- Coder-Strike 2014 - Finals (online edition, Div. 1)
- Coder-Strike 2014 - Finals (online edition, Div. 1)
- Coder-Strike 2014 - Finals (online edition, Div. 2) D.Bug in Code
- Coder-Strike 2014 - Finals (online edition, Div. 2) C题
- Coder-Strike 2014 - Finals (online edition, Div. 1) C. Bug in Code
- Coder-Strike 2014 - Finals (Div. 2) A. Pasha and Hamsters
- Coder-Strike 2014 - Finals Div 2
- Coder-Strike 2014 - Finals ( Div. 2) B. Start Up
- 【Codeforces】【Coder-Strike 2014 - Finals】【E Cup Trick】【题解】