codeforces#239_div2_B Garland 简单模拟
来源:互联网 发布:淘宝企业店铺升级流程 编辑:程序博客网 时间:2024/06/05 16:58
题目地址:戳这里
题目大意;剪成花环,可以cut 但是不能粘贴--那么最多的方案就是,对每一种具体的颜色,第一字符串中出现的次数和第二个字符串中出现的次数取较小值。
先以为not obliged to 是不应该.... 最后发现是不必须,,,, 注释flag那掉一行就行了
代码:
#include<iostream>#include<string>#include<map>using namespace std;int min(int a,int b){ return a<b?a:b;}int main(){ map<char,int> map_a,map_b; string a,b; cin>>a>>b; for(int i=0;i<a.length();i++) map_a[a[i]]++; for(int i=0;i<b.length();i++) map_b[b[i]]++; map<char,int> ::iterator it,it1; bool ok=1; // for(it=map_a.begin();it!=map_a.end();it++)// {// if(it->second>1) {// ok=1;// break;// }// }// bool flag=0; int ans=0; for(it=map_b.begin();it!=map_b.end();it++) { it1=map_a.find(it->first); if(it1==map_a.end()) { ok=0; break; } else { if(it1->second>1) flag=1; ans+=min(it->second,it1->second); } } //if(!flag) ok=0; if(!ok) { cout<<-1<<endl; } else cout<<ans<<endl; return 0; }
0 0
- codeforces#239_div2_B Garland 简单模拟
- Garland(CodeForces
- codeforces#237_div2_B Marathon
- Codeforces Round #239 (Div. 2) B. Garland(字符串统计题目,简单题)
- Codeforces Round #239 (Div. 2) B. Garland
- codeforces#238_div2_B Domino Effect
- codeforces-758-B Blown Garland(简单数学)
- codeforces 408B Garland
- 【Codeforces 758 Blown Garland】
- Codeforces 767C Garland
- Blown Garland CodeForces
- codeforces 767C Garland
- codeforces#233_div2_B Red and Blue Balls
- codeforces#235_div2_B Sereja and Contests
- codeforces#236_div2_B Trees in a Row
- codeforces#154_div2_B (253B) Physics Practical
- codeforces#219_div2_B Making Sequences is Fun
- codeforces#240_div2_B Mashmokh and Tokens
- C语言之联合体union
- #pragma pack(n)的作用
- 简单实现tableView折叠列表
- 新站排名急剧下跌为哪般?
- zoj 3725 Painting Storages 题解
- codeforces#239_div2_B Garland 简单模拟
- C语言头文件的使用
- 作业(第四周)
- ZOJ-3116
- linux网络编程十三:I/O复用select
- linux服务器 通过nfs挂载存储需要开portmap服务
- getApplication和Activity.this的区别
- UML中6大关系分析
- 改善你的电池寿命十倍PureMotive