思路:直接暴力判断就OK了

 #include<bits/stdc++.h>

 using namespace std;
#define int long long signed main(){
int _;cin>>_;
while(_--){
string str;
cin>>str;
if(str.size()==){
if(str[]!='?'){
cout<<str<<'\n';
}else{
printf("a\n");
}
continue;
}
int flag=;
for(int i=;i<str.size();i++){
if(str[i]=='?'){
int temp1=;int temp2=;
if(i->=){
if(str[i-]=='a'){
temp1=;
}else if(str[i-]=='b'){
temp1=;
}else if(str[i-]=='c'){
temp1=;
}else{
temp1=-;
}
}
if(i+<str.size()){
if(str[i+]=='a'){
temp2=;
}else if(str[i+]=='b'){
temp2=;
}else if(str[i+]=='c'){
temp2=;
}else{
temp2=-;
}
}
if(temp1==-&&temp2==-){
str[i]='a';
}else if(temp1==temp2){
if(temp1==){
str[i]='b';
}else if(temp1==){
str[i]='a';
}else if(temp1==){
str[i]='a';
}
}else{
map<int,int> vis;
vis[temp1]=;
vis[temp2]=;
int F=;
for(int i=;i<=;i++){
if(!vis[i]){
F=i;
break;
}
}
if(F==){
str[i]='a';
}else if(F==){
str[i]='b';
}else if(F==){
str[i]='c';
}
}
}
}
for (int i=;i<str.size()-;i++){
if(str[i]==str[i+]){
flag=;
break;
}
}
if(flag){
cout<<"-1"<<'\n';
continue;
}else{
cout<<str<<'\n';
}
}
return ;
}

思路:经过观察发现,排序后只要每个数对应的id是连续的就符合条件。

 #include<bits/stdc++.h>
#include<queue>
using namespace std;
#define int long long
#define N 1005000
#define inf 0x3f3f3f3f3f3f
struct str{
int num;
int id;
}st[N];
int ans[N];
bool cmp(str a,str b){
return a.num<b.num;
}
deque<int> q; // 维护最小值和最大值
signed main(){
int _;
cin>>_;
while(_--){
int n;
cin>>n;
ans[]=;
ans[n]=;
for(int i=;i<=n;i++){
scanf("%lld",&st[i].num);
st[i].id=i;
}
sort(st+,st++n,cmp);
/*
for(int i=1;i<=n;i++){
printf("%lld %lld\n",st[i].num,st[i].id);
}
*/
int minx=inf;
int maxn=(-)*inf;
minx=min(st[].id,minx);
maxn=max(maxn,st[].id);
for(int i=;i<n;i++){
minx=min(st[i].id,minx);
maxn=max(maxn,st[i].id);
int dis=;
dis=maxn-minx+;
if(i==dis){
ans[i]=;
}else{
ans[i]=;
} }
for(int i=;i<=n;i++) printf("%lld",ans[i]);
printf("\n");
for(int i=;i<=n+;i++){
ans[i]=;
st[i].id=;st[i].num=;
}
}
return ;
}

思路:题目对于g有大小限制而s和b之间没有,则我们让g尽可能小就好了,即选解题数最高的那一组选手全部发金牌,然后发银牌,直到g>s,剩下的选手全部发铜牌,直到发的牌数恰好小于n/2即可,做不到则不可行。【模拟一下】

 #include<bits/stdc++.h>

 using namespace std;
#define int long long
#define N 1050025
#define inf 0x3f3f3f3f3f
int arr[N];
signed main(){
int _;cin>>_;
while(_--){
int n;
cin>>n;
int g=,s=,b=;
for(int i=;i<=n;i++){
scanf("%lld",&arr[i]);
}
if(n<){
cout<<"0 0 0\n";
continue;
}
int maxn_sum=n/;
int avg=maxn_sum/;
int sum_g=;int sum_s=;int sum_b=;
int now=;
for(int i=;i<=n&&i<=maxn_sum;i++,now++){
if(arr[i]==arr[i+]){
sum_g++;
}else{
break;
}
}
g=sum_g;
for(int i=now+;i<=n&&i<=maxn_sum;i++,now++){
if(sum_s<=sum_g){
sum_s++;
}else{
if(arr[i]==arr[i+]){
sum_s++;
}else{
break;
}
}
}
s=sum_s;
sum_b=maxn_sum-g-s;
b=sum_b;
if(sum_b<=g){
printf("0 0 0\n");
continue;
}
if(arr[maxn_sum]==arr[maxn_sum+]){
for(int i=maxn_sum;i>=;i--){
if(arr[i]==arr[i-]){
b--;
}else{
b--;
break;
}
}
}
if(b<=g||b<=||s<=||g<=||s<=g){
printf("0 0 0\n");
continue;
}else{
printf("%lld %lld %lld\n",g,s,b);
} }
return ;
}

D题待补。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

Codeforces Round #604 (Div. 2) A,B,C【D题待补】的更多相关文章

  1. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  2. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  3. Codeforces Round #604(Div. 2,

    // https://codeforces.com/contest/1265/problem/D /* 感觉像是遍历的思维构造题 有思路就很好做的 可以把该题想象成过山车或者山峰...... */ # ...

  4. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors

    链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...

  5. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  6. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  7. Codeforces Round #604 (Div. 2) B. Beautiful Numbers

    链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...

  8. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  9. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  10. Codeforces Round #604 (Div. 2) 部分题解

    链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...

随机推荐

  1. 数据分析-numpy的用法

    一.jupyter notebook 两种安装和启动的方式: 第一种方式: 命令行安装:pip install jupyter 启动:cmd 中输入 jupyter notebook 缺点:必须手动去 ...

  2. 【LEETCODE】35、169题, Majority Element

    package y2019.Algorithm.array; import java.util.HashMap; import java.util.Map; /** * @ProjectName: c ...

  3. 读写锁(ReentrantReadWriteLock)

    重点: 1.读锁共享 2.写锁互斥 3.读写锁互斥 锁降级:将写锁降级为读锁.(先获取写锁,再获取读锁,再释放写锁,最后释放读锁) 造成锁降级的原因:出于性能考虑,一般情况下,都将锁定的动作,精确到具 ...

  4. AGC028E High Elements 贪心、DP、线段树

    传送门 看到要求"字典序最小"的方案,一个很直观的想法是按位贪心,那么我们需要check的就是当某一个数放在了第一个序列之后是否还存在方案. 假设当前两个序列的最大值和前缀最值数量 ...

  5. springboot 2.1.3.RELEASE添加filter,servlet源码学习

    Servlet规范中,通过ServeltContext来注册Filter.Servlet,这里分析Filter,Servlet是相同逻辑 springboot2.0中,我们通过 FilterRegis ...

  6. PL/SQL不安装ORACLE客户端

    1.oracle官网下载instantclient,将包解压存放到本地. 在这个路径下D:\oracle-basic\instantclient_12_2\network\admin放入TNS文件. ...

  7. js 页面技巧

    需要获取页面上固定的某个按钮的属性值.我们需要在页面加载完的第一刻将值存储到定义的变量,防止用户更改页面样式读不出当前元素.如果页面刷新会重置当前属性 <body> <input v ...

  8. 【洛谷 P4302】 [SCOI2003]字符串折叠(DP)

    题目链接 简单区间dp 令\(f[i][j]\)表示\([i,j]\)的最短长度 先枚举区间,然后在区间中枚举长度\(k\),看这个区间能不能折叠成几个长度为\(k\)的,如果能就更新答案. #inc ...

  9. 【洛谷 P4070】 [SDOI2016]生成魔咒(后缀自动机)

    题目链接 建出\(SAM\)后,不同子串个数就是\(\sum len(i)-len(fa(i))\) 因为\(SAM\)在线的,所以每加入一个字符就能直接加上其贡献,于是这道题就没了. 因为\(x\) ...

  10. 【洛谷 P3224】 [HNOI2012]永无乡(Splay,启发式合并)

    题目链接 启发式合并就是暴力合并把小的合并到大的里,一个一个插进去. 并查集维护连通性,同时保证并查集的根就是所在Splay的根,这样能省去很多操作. #include <cstdio> ...