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的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...
随机推荐
- ShellExecute使用详解
ShellExecute命令 ⑴ 函数原型: HINSTANCE ShellExecute(HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTST ...
- 介绍一个axios调试好用的工具:axios-mock-adapter
上一篇文章中写到用promise时应注意的问题,这一篇文章继续介绍一个可以和axios库配合的好工具: axios-mock-adapter.axios-mock-adapter可以用来拦截http请 ...
- DataWorks使用小结(二)——功能面板使用指南
一.数据开发 1.任务开发 新建表 野路子可以直接新建一个任务,粘贴DDL,手动运行任务即可完成建表 正常应当是在“数据管理”->数据表管理中建表: 支持可视化建表和DDL建表(配合之前的宏,建 ...
- Ionic App之国际化(1)单个参数的处理
最近的app开发中需要考虑多语言国际化的问题,经查资料,目前大部分使用的是angular-translate.js这个组件,网站说明是这个:https://angular-translate.gith ...
- 决策树(ID3,C4.5,CART)原理以及实现
决策树 决策树是一种基本的分类和回归方法.决策树顾名思义,模型可以表示为树型结构,可以认为是if-then的集合,也可以认为是定义在特征空间与类空间上的条件概率分布. [图片上传失败...(image ...
- PAT甲级题解-1123. Is It a Complete AVL Tree (30)-AVL树+满二叉树
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6806292.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 《Linux内核设计与分析》第四章读书笔记
<内核设计与实现>第四章读书笔记 第四章:进程调度 进程(操作系统)程序的运行态表现形式. 进程调度程序,它是确保进程能有效工作的一个内核子系统. 调度程序负责决定将哪个进程投入运行,何时 ...
- 关于git的一些体会:
周忠贤github链接:https://github.com/zhouzhongxian git学习心得:通过这次的学习,体会到了许多东西只要你用心去做,就没有什么做不成,,这次体会到了网上学习的重要 ...
- Leetcode 279. 完全平方数
题目描述: https://leetcode-cn.com/problems/perfect-squares/ 解题思路: 同样是dp,一开始的想法是,对于每个数i做拆分为j和(i-j),利用动态转移 ...
- 第二个spring
由于第一个spring已经完成,我们现在进去第二个spring! 陈志棚:成绩的统筹 李天麟:界面音乐 徐侃:代码算法 plan好布局,分配任务,控制时间!