Educational Codeforces Round 107 (Rated for Div. 2)
题号 | 题目 | 知识点 |
---|---|---|
A | Review Site | 签到 |
B | GCD Length | 思维+构造 |
C | Yet Another Card Deck | 思维 |
D | Min Cost String | 构造题 |
E | Colorings and Dominoes | 思维题,构造题 |
F | Chainword | |
G | Chips on a Board |
A
题意:
有3种评论员,第一个会给电影赞,第二个会给电影踩,第三个如果当前踩的数量大于赞,就会给赞,否则给踩
现在有n个评论员,问赞最多是多少
题解:
把赞的评论员全部放前面,第三种放中间,踩的最后
赞的数量+中立-踩
代码:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w;
}
const int maxn=60;
int a[maxn];
int main()
{int t;cin>>t;while(t--){int n;cin>>n;int sum=0; int tot=0;for(int i=1;i<=n;i++){int x;cin>>x;if(x==1||x==3){sum++;}}cout<<sum<<endl;}return 0;
}
/*
反对>赞同 ×
赞同>=反对
4
1
2
3
1 2 3
5
1 1 1 1 1
3
3 3 2*/
C
题意:
一个序列,每次给出一个x,输出第一个出现x的坐标,并将其放到最前面,其他数顺位,有q个这样的操作
题解:
虽然数会有重复,但是只需要记录第一个出现的就行,后面出现的没影响,然后用数组模拟过程即可
a和t的范围很小,直接暴力就行
代码:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w;
}
const int maxn=800;
int b[maxn];
int v[maxn];
int main()
{int n,q;cin>>n>>q;int tot=0;for(int i=1;i<=n;i++){int x;cin>>x;if(b[x]!=0)continue;v[++tot]=x;//顺序存数 b[x]=i;//x的位置 }int x;for(int i=1;i<=q;i++){ cin>>x;cout<<b[x]<<" ";int pos;for(int i=1;i<=tot;i++){if(v[i]==x){pos=i;break;}}for(int i=1;i<pos;i++){b[v[i]]++;}for(int i=pos;i>=2;i--){v[i]=v[i-1];//往后移动一次 }b[x]=1;v[1]=x;}return 0;
}