codeforces-1144 (div3)
赛后经验:div3过于简单,以后不做了
A.存在以下情况即为NO
1.存在相同字母 2.最大字母-最小字母 != 字符串长度
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
bool vis[maxn];
char str[maxn];
int main(){
int T = read();
while(T--){
scanf("%s",str);
int l = strlen(str);
int MIN = INF,MAX = ,flag = ;
for(int i = ; i < ; i ++) vis[i] = ;
for(int i = ; i < l ; i ++){
if(vis[str[i] - 'a']){
flag = ;
continue;
}
vis[str[i] - 'a'] = ;
MIN = min(MIN,str[i] - 'a');
MAX = max(MAX,str[i] - 'a');
}
if(MAX - MIN + == l && flag){
puts("Yes");
}else{
puts("No");
}
}
return ;
}
A
B.设奇数字母cnt1个,偶数字母cnt2个
假设cnt1 >= cnt2 最多留下(cnt1 - cnt2 - 1)个奇数字母,偶数同理
取最小的保留就可以了
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int even[maxn],odd[maxn];
int main(){
Sca(N);
int cnt1 = ,cnt2 = ;
for(int i = ; i <= N ; i ++){
int x = read();
if(x & ) odd[++cnt1] = x;
else even[++cnt2] = x;
}
sort(odd + ,odd + cnt1 + );
sort(even + ,even + + cnt2);
if(abs(cnt1 - cnt2) <= ){
puts("");
}else if(cnt1 > cnt2){
LL sum = ;
for(int i = ; i <= cnt1 - cnt2 - ;i ++) sum += odd[i];
Prl(sum);
}else{
LL sum = ;
for(int i = ; i <= cnt2 - cnt1 - ;i ++) sum += even[i];
Prl(sum);
}
return ;
}
B
C.很显然一个数出现次数超过3次就NO
第一个数列输出所有次数 >= 1的数
第二个数列输出所有次数 >= 2的数即可
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int ans[maxn];
int main(){
Sca(N);
int MAX = -,MIN = INF;
bool flag = ;
for(int i = ; i <= N; i ++){
int x = read();
a[x]++;
if(a[x] > ) flag = ;
MAX = max(MAX,x); MIN = min(MIN,x);
}
if(!flag){
puts("NO");
return ;
}
puts("YES");
int top = ;
for(int i = MIN; i <= MAX; i ++){
if(a[i]){
a[i]--;
ans[++top] = i;
}
}
Pri(top);
for(int i = ; i <= top; i ++) printf("%d ",ans[i]);
puts("");
top = ;
for(int i = MAX; i >= MIN; i --){
if(a[i]) ans[++top] = i;
}
Pri(top);
for(int i = ; i <= top; i ++) printf("%d ",ans[i]);
puts("");
return ;
}
C
D.仔细一看就会发现操作就是把一个数变为相邻的一个数。
那么出现最多次数的数不变,其余的都变成他就可以了。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int num[maxn];
int main(){
Sca(N);
int MAX = ;
for(int i = ; i <= N ; i ++){
Sca(a[i]); num[a[i]]++;
if(num[MAX] < num[a[i]]) MAX = a[i];
}
int root = ;
int ans = ;
Pri(N - num[MAX]);
for(int i = ; i <= N ; i ++){
if(a[i] == MAX){
root = i;
break;
}
}
for(int i = root + ; i <= N; i ++){
if(a[i] > a[i - ]) printf("2 %d %d\n",i,i - );
else if(a[i] < a[i - ]) printf("1 %d %d\n",i,i - );
a[i] = a[i - ];
}
for(int i = root - ; i >= ; i --){
if(a[i] > a[i + ]) printf("2 %d %d\n",i,i + );
else if(a[i] < a[i + ]) printf("1 %d %d\n",i,i + );
a[i] = a[i + ];
}
return ;
}
D
E.模拟26进制加减法即可。具体操作就是(a + b) / 2
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
char a[maxn],b[maxn];
int c[maxn];
int main(){
N = read();
scanf("%s%s",a + ,b + );
for(int i = N ; i >= ; i--){
c[i] += b[i] + a[i] - 'a' - 'a' + ;
while(c[i] > ){
c[i] -= ;
c[i - ]++;
}
}
int zero = ;
for(int i = ; i <= N ; i ++){
if(c[i] & ){
c[i]--;
c[i + ] += ;
}
c[i] /= ;
if(c[i]) zero = ;
if(!zero) printf("%c",c[i] + 'a' - );
}
return ;
}
E
F.意识到一个点不会即有入度又有出度,那么所有点就分为了出度点和入度点。
直接图上染色即可。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 2e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
struct Edge{
int to,next;
}edge[maxn * ];
int head[maxn],tot;
void init(){
for(int i = ; i <= N; i ++) head[i] = -;
tot = ;
}
void add(int u,int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
}
int color[maxn];
bool flag = ;
void dfs(int t){
if(!flag) return;
for(int i = head[t]; ~i ; i = edge[i].next){
int v = edge[i].to;
if(color[v] == color[t]){
flag = ;
return;
}
if(color[v] == - color[t]) continue;
color[v] = - color[t];
dfs(v);
}
}
PII E[maxn];
int main(){
Sca2(N,M); init();
for(int i = ; i <= M; i ++){
int u = read(),v = read();
add(u,v); add(v,u);
E[i] = mp(u,v);
}
for(int i = ; i <= N && flag; i ++){
if(!color[i]){
color[i] = ;
dfs(i);
}
}
if(!flag){
puts("NO"); return ;
}else{
puts("YES");
}
for(int i = ; i <= M ; i ++){
if(color[E[i].fi] == ) printf("");
else printf("");
}
return ;
}
F
G.题目的一个子问题是序列中的一个区间能否分为递增和递减
意识到一个区间最小的点,只能作为递增的起点或者递减的终点,在知道了这个条件下,另一边就已知必须递增或者递减。
预处理出每个点为起点的最大递增终点和最大递减终点。
用solve(l,r,lMIN,lMAX,rMIN,rMAX)表示在l到r这段区间内,递减段的数字被限制在lMIN到lMAX内,递增段的数字被限制在rMIN,rMAX内,在此基础上求是否可行。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 8e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn],Hash[maxn];
struct tree{
int l,r,MIN;
}tree[maxn << ];
void Pushup(int t){
if(a[tree[t << ].MIN] < a[tree[t << | ].MIN]) tree[t].MIN = tree[t << ].MIN;
else tree[t].MIN = tree[t << | ].MIN;
}
void Build(int t,int l,int r){
tree[t].l = l; tree[t].r = r;
if(l == r){
tree[t].MIN = l;
return;
}
int m = l + r >> ;
Build(t << ,l,m); Build(t << | ,m + ,r);
Pushup(t);
}
int query(int t,int l,int r){
if(l <= tree[t].l && tree[t].r <= r) return tree[t].MIN;
int m = tree[t].l + tree[t].r >> ;
if(r <= m) return query(t << ,l,r);
else if(l > m) return query(t << | ,l,r);
else{
int p1 = query(t << ,l,m),p2 = query(t << | ,m + ,r);
if(a[p1] > a[p2]) return p2;
return p1;
}
}
int ans[maxn];
int radd[maxn],rdel[maxn];
bool solve(int L,int R,int lMIN,int lMAX,int rMIN,int rMAX){
if(L > R) return true;
if(L == R){
if(rMIN < a[L] && a[L] < rMAX){
ans[L] = ;
return true;
}
if(lMIN < a[L] && a[L] < lMAX){
ans[L] = ;
return true;
}
return false;
}
int p = query(,L,R);
if(lMIN < a[p] && a[p] < lMAX && (p == R || (radd[p + ] >= R && a[p + ] > rMIN && a[p + ] < rMAX && a[R] < rMAX && a[R] > rMIN))){
if(solve(L,p - ,a[p],lMAX,rMIN,p == R?rMAX:a[p + ])){
ans[p] = ;
for(int j = p + ; j <= R; j ++) ans[j] = ;
return true;
}
}
if(rMIN < a[p] && a[p] < rMAX && (p == L || (rdel[L] >= p - && a[L] > lMIN && a[L] < lMAX && a[p - ] < lMAX && a[p - ] > lMIN))){
if(solve(p + ,R,lMIN,p == L?lMAX:a[p - ],a[p],rMAX)){
ans[p] = ;
for(int j = L; j <= p - ; j ++) ans[j] = ;
return true;
}
}
return false;
}
int main(){
Sca(N);
for(int i = ; i <= N ; i ++) a[i] = read();
radd[N] = rdel[N] = N;
for(int i = N - ; i >= ; i --){
if(a[i] < a[i + ]) radd[i] = radd[i + ];
else radd[i] = i;
if(a[i] > a[i + ]) rdel[i] = rdel[i + ];
else rdel[i] = i;
}
Build(,,N);
if(solve(,N,-INF,INF,-INF,INF)){
puts("YES");
for(int i = ; i <= N ; i ++) printf("%d ",ans[i]);
}else{
puts("NO");
}
return ;
}
G
codeforces-1144 (div3)的更多相关文章
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- codeforces #579(div3)
codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...
- Codeforces 1144 E. Median String
原题链接:https://codeforces.com/problemset/problem/1144/E tag:字符串模拟,大整数. 题意:给定两个字符串,求字典序中间串. 思路:可以把这个题当做 ...
- CodeForces 1029E div3
题目链接 第一道场上自己做出来的E题...虽然是div3,而且是原题... 当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题? 事实上就是原题... 给个原题链接... [HNOI2003]消 ...
- [Codeforces #615 div3]1294E Obtain a Permutation
Before the Beginniing 本文为 Clouder 原创文章,原文链接为Click,转载时请将本段放在文章开头显眼处.如进行了二次创作,请明确标明. 由本人转载于博客园. 题意分析 C ...
- Codeforces #624 div3 C
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- Twist the Permutation 数列的轮换题 Codeforces 776 div3
这是一道比较经典的将数列中的数字轮换的题目,我们先看题干: 题干分析:先浅浅地分析一下题目是要我们干什么,我们会默认有一个已经升序排序地1~n的排列,然后我们会给定一个新排列是在原有排列的基础上进行o ...
- 记一次神奇的codeforces
今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
随机推荐
- 微信小程序之菜鸟入门教学(二)
昨天学习了一些简单的概念,今天开始实际操作,通过搭建简单的计算器来学习小程序的架构 一.小程序框架 程序框架如上图所示.由此可见,框架的基本构成为: 1. app.js . app.wxss 2. a ...
- python xlrd 读取excel.md
文章链接:https://mp.weixin.qq.com/s/fojkVO-AB2cCu7FtDtPBjw 之前的文章介绍过关于写入excel表格的方法,近期自己在做一个网站,涉及到读取excel, ...
- deepin linux学习笔记(四)进不去图形界面怎么办?
目录 deepin linux学习笔记(四)进不去图形界面怎么办? 前言 更换成lxde桌面 进不去图形界面怎么办? 总结 deepin linux学习笔记(四)进不去图形界面怎么办? 前言 生命不息 ...
- sql 上舍下舍運用
[四舍五入取整截取] select round(54.56,0) [向下取整截取] SELECT FLOOR(54.56) [向上取整截取] SELECT CEILING(13.15) --MS ...
- Python 进程(一)理论部分
进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行,即正在运行的程序,是系统进行资源分配和调度的基本单位,进程是对正在运行程序的一个抽象,在早期面向进程设计的计算机结构中,进程是程 ...
- phpdocumentor 安装以及使用说明
一 缘由 最近改版公司网站和app端的api,发现很多函数和方法都没写注释,搞得每次调用之前还需要看底层实现,有的方法名和功能还类似,区分不出使用哪个最优!为了避免给后人挖坑,除了将代码写得规范外, ...
- 如何快速搭建一个基于ServiceStack框架的web服务
ServiceStack是一个高性能的.NET Web Service 平台,能够简化开发高性能的REST (支持JSON,XML,JSV,HTML,MsgPack,ProtoBuf,CSV等消息格式 ...
- Linux 下的 python 虚拟环境 + vim快捷方式
day04虚拟环境 https://www.cnblogs.com/pyyu/p/9015317.html 博客 关闭防火墙: systemctl stop firewalld # 关闭防火前 sys ...
- AppCan移动开发技巧:3步走,获取移动APP签名信息
大家知道,在移动APP开发里,与应用包名一样,应用的签名信息需是唯一的,否则将会出现应用冒领.重复安装等问题.之前分享过安卓应用的签名如何获取(点击查看),这里将继续以AppCan平台为例,分享如何获 ...
- facebook marketing(市场营销) API(3)
如果你只想管理广告,而不想管理BM,那就需要市场营销API了. 相关文章 通过BM api管理完相互授权后,就可以让自己的运营参与进行投放了(市场营销API也支持非BM操作,即广告主自己操作). 市场 ...