Codeforces Round #436 (Div. 2) A,B,D
A. Fair Game
题目链接:http://codeforces.com/contest/864/problem/A
水题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int MAX=1e5+;
const double eps=1e-;
const double mod=1e9+;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define useit ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
//struct num{int v,i;}l[MAX],r[MAX];
//bool cmp(const num &x, const num &y){return x.v<y.v;} int main()
{
int n,a[MAX],b,t=,s1=,s2=;
FOR(i,,)a[i]=;
cin>>n;
FOR(i,,n)
{
cin>>b;
if(!a[b])
t++;
a[b]++;
}
if(t==)
{
FOR(i,,) if(a[i]){s1=i;break;}
ROF(i,,) if(a[i]){s2=i;break;}
if(a[s1]==a[s2]&&s1!=s2)
cout<<"YES"<<endl<<s1<<" "<<s2<<endl;
else
cout<<"NO"<<endl;
}
else
cout<<"NO"<<endl;
}
B. Polycarp and Letters
题目链接:http://codeforces.com/contest/864/problem/B
水题,写太急了,忘了考虑全是小写字母的情况,wa了两发血亏。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1e9+;
const int M = 1e5+;
map<char,int>mp;
int main()
{
int n,maxx;
char s[];
cin>>n;
for(int i=;i<n;i++)
cin>>s[i];
maxx = -inf;
int ans = ;
for(char i = 'a';i<='z';i++){
mp[i] = ;
}
for(int i=;i<n;i++){
if(s[i]>='a'&&s[i]<='z'){
if(mp[s[i]]==)
{
ans++;
mp[s[i]]=;
}
}
else{
maxx = max(ans,maxx);
ans = ;
for(char i = 'a';i<='z';i++){
mp[i] = ;
}
}
}
maxx = max(ans,maxx);
cout<<maxx<<endl;
return ;
}
D. Make a Permu!
题目链接:http://codeforces.com/contest/864/problem/D
题目有点水,直接暴力过了。。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1e9+;
const int M = 2e5+;
map<int,int>mp;
int a[M],flag[M];
int main()
{
int n,maxx,i,j;
cin>>n;
maxx = -inf;
memset(flag,,sizeof(flag));
int cnt = ;
for(i=;i<n;i++){
cin>>a[i];
mp[a[i]]++;
if(mp[a[i]]>)
cnt++;
maxx = max(a[i],maxx);
}
int l=;
for(i=;i<n;i++){
if(mp[a[i]]>){
for(j=l+;j<=M;j++){
if(mp[j]==){
mp[j]==;
l = j;break;
}
}
//cout<<l<<endl;
if(l<a[i]){
//cout<<mp[a[i]]<<endl;
mp[a[i]]-=,a[i]=l; //之前这里先替换再标记。搞得wa了一发,血亏。。还好学长出了发神样例查到了
//cout<<mp[a[i]]<<endl;
}
else{
if(flag[a[i]]==){
mp[a[i]]--,a[i]=l;
}
else{
mp[l]==;l--;
flag[a[i]] = ;
}
}
}
}
cout<<cnt<<endl;
for(i=;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
return ;
}
Codeforces Round #436 (Div. 2) A,B,D的更多相关文章
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- Codeforces Round #436 (Div. 2) C. Bus
http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a ...
- Codeforces Round #436 (Div. 2) E. Fire
http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...
- Codeforces Round #436 (Div. 2)
http://codeforces.com/contest/864 第一次打cf的月赛-- A 题意:给你一个数列,问你能不能保证里面只有两种数且个数相等.2<=n<=100,1<= ...
- Codeforces Round #436 (Div. 2) D. Make a Permutation!
http://codeforces.com/contest/864/problem/D 题意: 给出n和n个数(ai <= n),要求改变其中某些数,使得这n个数为1到n的一个排列,首先保证修改 ...
- Codeforces Round #436 (Div. 2) B. Polycarp and Letters
http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字 ...
- Codeforces Round #436 (Div. 2)D. Make a Permutation! 模拟
D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...
- Codeforces Round #436 (Div. 2)C. Bus 模拟
C. Bus time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input out ...
- 【做题】Codeforces Round #436 (Div. 2) F. Cities Excursions——图论+dfs
题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...
随机推荐
- ${pageContext.request.contextPath}的作用【转载】
原文地址:http://ps329795485-126-com.iteye.com/blog/1290662 刚开始不知道是怎么回事,在网上也查找了一些资料,看了还是晕. 看了另一个大侠的,终于有了点 ...
- php实现一个简单的四则运算计算器
php实现一个简单的四则运算计算器(还不支持括号的优先级).利用栈这种数据结构来计算表达式很赞. 这里可以使用栈的结构,由于php的数组“天然”就有栈的特性,这里直接就利用了数组.当然可以使用栈结构写 ...
- Literal 字面值 字面量 的理解
Literal 字面值 字面量 Literal, 在程序语言中,指表示某种数据值的符码.如,123 是整数值符码, 3.14 是浮点值符码,abcd 是字串值符码,True, False, 是逻辑值符 ...
- 微软被传证实收购 GitHub
GitHub 是一个庞大的代码库,已经有越来越多的公司使用这个网站来共享和查看代码,其中不乏苹果.亚马逊.谷歌等大型科技公司.微软则是该网站的最大贡献者,并有超过 1000 名员工长期地将代码推送到 ...
- 走近SpringBoot
(博客园不支持MarkDown编辑,看完整版请移步:https://www.zybuluo.com/Allen-llh/note/1199946) 1. (Building a RESTful Web ...
- 【vue】chrome已安装Vue Devtools在控制台却无显示
chrome已安装Vue Devtools在控制台却无显示的解决: 在点亮Vue Devtools图标后,控制台没有vue解读显示. 原因:脚手架配置NODE_ENV直接定义为了production版 ...
- CF1038E Maximum Matching 搜索/区间DP
题目传送门:http://codeforces.com/problemset/problem/1038/E 题意:给出$N$个方块,每个方块有左右两种颜色$a,b$(可以翻转使左右两种颜色交换)和一个 ...
- 编写自己的dapper lambda扩展-使用篇
前言 这是针对dapper的一个扩展,支持lambda表达式的写法,链式风格让开发者使用起来更加优雅.直观.现在暂时只有MsSql的扩展,也没有实现事务的写法,将会在后续的版本补充. 这是个人业余的开 ...
- PHP从入门到精通(三)
PHP数组的分类 按照下标的不同,PHP数组分为关联数组与索引数组: 索引数组:下标从0开始,依次增长:关联数组: 下标为字符串格式,每个下标字符串与数组的值一一关联对应.(有点像对象的键值对) 关于 ...
- 12.17 Daily Scrum
Today's Task Tomorrow's Task 丁辛 实现和菜谱相关的餐厅列表. 实现和菜谱相关的餐厅列表. 邓亚梅 美化搜索框UI. 美 ...