日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cf#401(Div. 2)B. Game of Credit Card(田忌赛马类贪心)

發布時間:2023/12/10 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cf#401(Div. 2)B. Game of Credit Card(田忌赛马类贪心) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.

Rules of this game are simple: each player bring his favourite?n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if?n?=?3, Sherlock's card is?123?and Moriarty's card has number?321, first Sherlock names?1?and Moriarty names?3?so Sherlock gets a flick. Then they both digit?2?so no one gets a flick. Finally, Sherlock names?3, while Moriarty names?1?and gets a flick.

Of course, Sherlock will play honestly naming digits one by one in 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 to change the overall number of occurences of each digit). For example, in case above Moriarty could name?1,?2,?3?and get no flicks at all, or he can name?2,?3?and?1?to give Sherlock two flicks.

Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.

Input

The first line of the input contains a single integer?n?(1?≤?n?≤?1000)?— the number of digits in the cards Sherlock and Moriarty are going to use.

The second line contains?n?digits?— Sherlock's credit card number.

The third line contains?n?digits?— Moriarty's credit card number.

Output

First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.

Examples Input3 123 321 Output0 2 Input2 88 00 Output2 0 Note

First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.


題目大意:

? ? 夏洛克和她玩起了彈腦殼的游戲。。。他們都拿到n個數字,并且夏洛克只能按照順序念,她耍賴,可以挑著念(改變順序)。然后,對于他們每一次念的數字,數字大的人可以給數字小的人一個腦瓜崩。問狡猾的她少可以被彈幾次,&最多可以彈夏洛克幾次?

解題報告:

? ? 都是從小到大同序排序,然后挨個比較,類似田忌賽馬,所以叫田忌賽馬貪心。(從大到小亦可解?)


ac代碼:

#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int a[1000+5]; int b[1000+5];int main() {int n;int ans1=0,ans2=0;cin>>n;for(int i = 0; i<n; i++) {scanf("%1d",&a[i]);}for(int i = 0; i<n; i++) {scanf("%1d",&b[i]);} // for(int i = 0; i<3; i++) { // printf("%d %d\n",a[i],b[i]); // }sort(a,a+n);sort(b,b+n);int i=0,j=0;//a[i],b[j]對應 //解ans1 while(i<n&&j<n) {if(b[j]>=a[i]) {i++;j++;ans1++;}else if(b[j]<a[i]){j++;}}ans1=n-ans1;i=0;j=0;//解ans2 while( i < n && j < n) {if(b[j]>a[i]) {ans2++;i++;j++;}if(b[j]<=a[i]) {j++;}}printf("%d\n%d",ans1,ans2);return 0 ;} 雙端隊列ac #include<cstdio> #include<queue> #include<deque> #include<algorithm> using namespace std; int main() {char str1[1000+11],str2[1000+11];int a,b,n;while(~scanf("%d",&n)){deque<int> q1,q2;deque<int> s1,s2;scanf("%s %s",str1,str2);for(int i=0;i<n;i++){a=str1[i]-'0';q1.push_back(a);b=str2[i]-'0';q2.push_back(b); }sort(q1.begin() ,q1.end() );sort(q2.begin() ,q2.end() );int k1,k2,v1,v2;int num1=n,num2=0;for(int i=1;i<=n;i++){k1=q1.back() ;k2=q2.back() ;if(k2>k1){num2++;s1.push_back(k1);s2.push_back(k2);q1.pop_back() ;q2.pop_back() ;continue; }v1=q1.front() ;v2=q2.front() ;if(v2>v1){num2++;s1.push_back(v1);s2.push_back(v2);q1.pop_front() ;q2.pop_front() ; }else{s1.push_back(k1);s2.push_back(v2);q1.pop_back() ;q2.pop_front() ; }}sort(s1.begin() ,s1.end() );sort(s2.begin() ,s2.end() );for(int i=1;i<=n;i++){if(s2.back() >=s1.back() ){num1--;s1.pop_back() ;s2.pop_back() ;continue;}v1=s1.front() ;v2=s2.front() ;if(v2>=v1){num1--;s1.pop_front() ;s2.pop_front() ;}else{s1.pop_back() ;s2.pop_front() ;}}printf("%d\n%d\n",num1,num2);}return 0;}


總結

以上是生活随笔為你收集整理的cf#401(Div. 2)B. Game of Credit Card(田忌赛马类贪心)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 6080亚洲精品一区二区 | 99riav国产精品视频 | 欧美多人猛交狂配 | 欧美日韩一二三四 | 欧洲自拍一区 | 尹人av| 欧洲在线视频 | 久草影音 | 九九这里只有精品视频 | 在线播放无码后入内射少妇 | 国产欧洲亚洲 | 另类欧美亚洲 | 熊出没之冬日乐翻天免费高清观看 | 久久久久久蜜桃一区二区 | 人人插人人插 | 国产原创在线播放 | 欧美情趣视频 | 成人在线视频免费观看 | 国产三级网站 | 青青草在线播放 | 91看片国产 | 91久久伊人 | av中亚| 亚洲乱码国产乱码精品精 | 亚洲成人www | 椎名由奈av一区二区三区 | 欧美77777| 久久午夜夜伦鲁鲁一区二区 | 福利影院av| 亚洲乱码国产乱码精品精的特点 | 中文字幕在线视频日韩 | 俄罗斯精品一区二区三区 | 亚洲精品wwww | 女女h百合无遮涩涩漫画软件 | 亚洲激情图 | 69视频在线播放 | www.色妞 | 欧美黄色影院 | 人妻 校园 激情 另类 | 欧美日韩视频在线观看一区 | 日本波多野结衣在线 | 偷拍一区二区三区四区 | 欧美精品在线观看一区二区 | 欧美片免费网站 | 韩国三级做爰视频 | 久久无毛 | 蜜臀久久99精品久久久无需会员 | 蜜臀在线观看 | 性色AV无码久久一区二区三 | 青青艹视频| 在线久草 | 色妇网| 亚洲成人黄色影院 | 中文亚洲字幕 | 国产一级一级国产 | 午夜免费看视频 | 久久伊人精品 | 亚洲日本精品一区 | 欧美日韩一区精品 | 91网页在线观看 | 国产三级av在线播放 | 激情五月网站 | 亚洲日本色图 | 人妻一区二区视频 | 综合色播| 好吊妞这里有精品 | 久久精品牌麻豆国产大山 | 成人免费激情视频 | 99热一区二区 | 嫩草懂你| 99久久免费精品 | 黄色在线免费 | 亚洲私人网站 | 制服丝袜在线看 | 图片区 小说区 区 亚洲五月 | 91高清免费 | 91拔萝卜视频 | 久久嗨 | 国产一区二区三区www | 中文字幕亚洲一区二区三区五十路 | 亚洲视频www | 特黄做受又粗又大又硬老头 | 亚洲精品中文字幕在线 | 双乳被四个男人吃奶h文 | 欧美大片在线看免费观看 | 97人人艹 | 日本少妇做爰全过程毛片 | 天天爽天天爱 | 国产欧美精品一区二区三区app | 丰满少妇被猛烈进入一区二区 | 美女尻逼视频 | 男人综合网 | 国产精品精品视频 | 亚洲欧美日韩色 | 日韩麻豆视频 | 成人午夜在线 | 久草电影在线 | 国内黄色片 | 黄色片视频免费在线观看 |