【CodeForces 777B】Game of Credit Cards(贪心+排序)
2017-02-25 09:51
411 查看
Game of Credit Cards
Problem Description
Afterthe fourth season Sherlock and Moriary have realized the whole foolishness ofthe battle between them and decided
to continue their competitions in peacefulgame of Credit Cards.
Rules of this game are simple: each player bring his favouriten-digit
credit card. Thenboth players name the digits written on their cards one by one. If two digitsare not equal, then the player, whose digit is smaller gets a flick (knock inthe forehead usually made with a forefinger) from the other player. For example,ifn = 3,
Sherlock's card is 123and
Moriarty's card hasnumber321,
first Sherlock names1 and
Moriarty names 3so
Sherlock gets a flick.Then they both digit2so
no one gets a flick.Finally, Sherlock names3,
while Moriarty names 1and
gets a flick.
Of course, Sherlock will play honestly naming digits one by onein the order they are given, while Moriary, as a true villain, plans to cheat.He is going to name
his digits in some other order (however, he is not going tochange the overall number of occurences of each digit). For example, in caseabove Moriarty could name1,2,3and
get no flicks at all,or he can name2,3and1to
give Sherlock twoflicks.
Your goal is to find out the minimum possible number of flicksMoriarty will get (no one likes flicks) and the maximum possible number offlicks Sherlock can get
from Moriarty. Note, that these two goals are differentand the optimal result may be obtained by using different strategies.
Input
The first line of the input contains a single integern(1 ≤ n ≤ 1000)
—the number of digits in the cards Sherlock and Moriarty are going to use.
The second line containsndigits
— Sherlock's creditcard number.
The third line containsndigits
— Moriarty's creditcard number.
Output
First print the minimum possible number offlicks Moriarty will get. Then
print the maximum possible number of flicks thatSherlock can get from Moriarty.
![](https://img-blog.csdn.net/20170225094926885?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZnNtbV9ibG9n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
Game of Credit Cards
Problem Description
Afterthe fourth season Sherlock and Moriary have realized the whole foolishness ofthe battle between them and decided
to continue their competitions in peacefulgame of Credit Cards.
Rules of this game are simple: each player bring his favouriten-digit
credit card. Thenboth players name the digits written on their cards one by one. If two digitsare not equal, then the player, whose digit is smaller gets a flick (knock inthe forehead usually made with a forefinger) from the other player. For example,ifn = 3,
Sherlock's card is 123and
Moriarty's card hasnumber321,
first Sherlock names1 and
Moriarty names 3so
Sherlock gets a flick.Then they both digit2so
no one gets a flick.Finally, Sherlock names3,
while Moriarty names 1and
gets a flick.
Of course, Sherlock will play honestly naming digits one by onein the order they are given, while Moriary, as a true villain, plans to cheat.He is going to name
his digits in some other order (however, he is not going tochange the overall number of occurences of each digit). For example, in caseabove Moriarty could name1,2,3and
get no flicks at all,or he can name2,3and1to
give Sherlock twoflicks.
Your goal is to find out the minimum possible number of flicksMoriarty will get (no one likes flicks) and the maximum possible number offlicks Sherlock can get
from Moriarty. Note, that these two goals are differentand the optimal result may be obtained by using different strategies.
Input
The first line of the input contains a single integern(1 ≤ n ≤ 1000)
—the number of digits in the cards Sherlock and Moriarty are going to use.
The second line containsndigits
— Sherlock's creditcard number.
The third line containsndigits
— Moriarty's creditcard number.
Output
First print the minimum possible number offlicks Moriarty will get. Then
print the maximum possible number of flicks thatSherlock can get from Moriarty.
#include<iostream> #include<cstdio> #include<algorithm> #define manx 1005 using namespace std; int main() { int n,a[manx]={0},b[manx]={0}; char c; scanf("%d",&n); getchar(); for (int i=0; i<n; i++){ //注意输入 scanf("%c",&c); a[i]=c-'0'; } getchar(); for (int i=0; i<n; i++){ scanf("%c",&c); b[i]=c-'0'; } sort(a,a+n); sort(b,b+n); int i,j,ans1=0,ans2=0; for (i=0,j=0; i<n && j<n; ){ if(b[j] >= a[i]){ i++; j++; } else { ans1++; j++; } } for (i=n-1,j=n-1; i>=0 && j>=0; ){ //田忌赛马 if(b[j] > a[i]){ ans2++; i--; j--; } else i--; } printf("%d\n%d\n",ans1,ans2); return 0; }
相关文章推荐
- codeforces 777 B. Game of Credit Cards (排序乱搞)
- cf 777B _ B. Game of Credit Cards (排序比较)
- Codeforces 777B-Game of Credit Cards
- codeforces 777B Game of Credit Cards (贪心)
- CodeForces - 609A USB Flash Drives ( 排序 简单贪心 )
- CodeForces 810B Summer sell-off 【贪心】【排序】
- codeforces-230A-Dragons(贪心+排序)
- Codeforces - 35D. Animals - 贪心+排序
- Codeforces 597B: Restaurant(贪心+结构体排序)
- Dragons(CodeForces 230A)(贪心和排序)
- Game of Credit Cards (贪心)
- 【CF】--- Game of Credit Cards (双端队列&&贪心)
- CF777B:Game of Credit Cards(贪心)
- Codeforces 3 B. Lorry 暴力 排序 枚举 贪心
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
- Codeforces Round #401 (Div. 2)B. Game of Credit Cards(贪心)
- codeforces 777 BGame of Credit Cards(贪心)
- Codeforces 556D Case of Fugitive【排序+贪心】
- Codeforces Round #401(Div. 2)B. Game of Credit Cards【贪心】
- Codeforces 3B.Lorry(贪心,排序)