Codeforces Round #604 (Div. 2) A,B,C【D题待补】
思路:直接暴力判断就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题待补】的更多相关文章
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- 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 ...
- Codeforces Round #604(Div. 2,
// https://codeforces.com/contest/1265/problem/D /* 感觉像是遍历的思维构造题 有思路就很好做的 可以把该题想象成过山车或者山峰...... */ # ...
- 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 ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- 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 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) 部分题解
链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...
随机推荐
- 协议——IIC
I²C即Inter-Integrated Circuit(集成电路总线),它是一种串行通信总线,使用多主从架构,由飞利浦公司在1980年代设计出来的一种简单.双向.二线制总线标准.多用于主机和从机在数 ...
- 3.01定义常量之define
[注:本程序验证是使用vs2013版] #include <stdio.h> #include <stdlib.h> #include <string.h> #pr ...
- .NET Core AvaloniaUI实现多语言国际化
AvaloniaUI是一个基于.Net Core的跨平台桌面程序UI框架,如果使用AvaloniaUI有多语言国际化的朋友可以参考我这篇文章: 这篇文章可以帮助你: 根据用户系统设置的语言改变UI显示 ...
- 跨域访问MVC
using MvcApp.Filters; using System; using System.Collections.Generic; using System.Linq; using Syste ...
- docker-每天5分钟玩转Docker容器技术
安装 https://www.cnblogs.com/qinxu/p/10032176.html 安装教程,目前只能安装到18版本的,安装完后执行下面命令更新到版本19 yum install doc ...
- Widget Size and Position !!!!!!!!!!!!!!!!!!
https://medium.com/@diegoveloper/flutter-widget-size-and-position-b0a9ffed9407 I have read many ques ...
- 【kubernetes】通过rancher2部署k8s
1. K8S相关介绍 十分钟带你理解Kubernetes核心概念 2. 部署rancher # 更新操作系统软件包 yum update -y # 删除历史容器及数据 docker rm -f $(d ...
- React Native 开发豆瓣评分(三)集成 Redux
什么是 redux redux 是一个用于管理 js 应用状态(state)的容器.比如组件 A 发生了变化,组件 B 要同时做出响应.常见的应用场景就是用户的登录退出操作:未登录状态,个人中心显示登 ...
- Linux REDHAT 7 关闭、禁用防火墙服务
1 查看防火墙状态 [root@lvxinghao ~]# systemctl status firewalld 2 查看开机是否启动防火墙服务[root@lvxinghao ~]# systemct ...
- 朴素贝叶斯算法源码分析及代码实战【python sklearn/spark ML】
一.简介 贝叶斯定理是关于随机事件A和事件B的条件概率的一个定理.通常在事件A发生的前提下事件B发生的概率,与在事件B发生的前提下事件A发生的概率是不一致的.然而,这两者之间有确定的关系,贝叶斯定理就 ...