Atcoder Beginner Contest 409 A-F
AB
#include<bits/stdc++.h>
using namespace std;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
int n;
string a,b;
int main(){
read(n);
cin>>a>>b;
bool ans=false;
for(int i=0;i<n;i++){
if(a[i]==b[i]&&a[i]=='o'){
ans=true;
}
}
if(ans) printf("Yes");
else printf("No");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
int n;
int a[maxn];
int main(){
read(n);
for(int i=1;i<=n;i++){
read(a[i]);
}
for(int i=n;i>=0;i--){
int cnt=0;
for(int j=1;j<=n;j++){
if(a[j]>=i) ++cnt;
}
if(cnt>=i){
printf("%d",i);
return 0;
}
}
return 0;
}
C
ABC很喜欢出圆的题目,但一般和几何关系不大
同圆当中,等弦所对的劣弧相同
若围成等边三角形,三条弧长必定相等
通过处理数据得到每个点在圆上的绝对位置,弧长必定是l/3
建立一个桶数组,遍历所有会出现圆的三个点,求乘积之和即可
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
int n,l;
int p[maxn];
int main(){
read(n),read(l);
int in,lst=0;
++p[0];
for(int i=2;i<=n;i++){
read(in);
lst=(lst+in)%l;
++p[lst];
}
if(l%3!=0){
printf("0");
return 0;
}
long long ans=0;
int tp=l/3;
for(int i=0;i<tp;i++){
ans+=1ll*p[i]*p[i+tp]*p[i+2*tp];
}
printf("%lld",ans);
return 0;
}
D
优先考虑最前面的进行交换,价值最大
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
struct st{
char c;
int p;
};
bool cmp(st a,st b){
return a.c<b.c;
}
st s[maxn];
char c[maxn];
int t,n;
int main(){
read(t);
while(t--){
read(n);
scanf("%s",c);
c[n]=255;
int l=-1,r=-1;
for(int i=0;i<n-1;i++){
if(c[i]>c[i+1]){
l=i,r=i+2;
while(r<n&&c[l]>=c[r]){
++r;
}
--r;
break;
}
}
for(int i=0;i<n;i++){
if(i==r) printf("%c",c[l]);
else if(i>=l&&i<r) printf("%c",c[i+1]);
else printf("%c",c[i]);
}
printf("\n");
}
return 0;
}
找右端点时,注意要跳过相等的情况
给组数据研究一下吧
7
dcdddca
E
不要想太多,就是一道非常简单的树上dp
卡第四题的我都没看第五题的simple程度
记得开long long
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
struct edge{
int v,w;
};
vector<edge> mp[maxn];
int t[maxn];
int n;
long long ans=0;
void dfs(int x,int fa){
for(int i=0;i<mp[x].size();i++){
int v=mp[x][i].v;
if(v==fa) continue;
dfs(v,x);
ans+=1ll*mp[x][i].w*abs(t[v]);
t[x]+=t[v];
}
return;
}
int main(){
read(n);
for(int i=1;i<=n;i++){
read(t[i]);
}
int u,v,w;
for(int i=1;i<=n-1;i++){
read(u),read(v),read(w);
mp[u].push_back((edge){v,w});
mp[v].push_back((edge){u,w});
}
dfs(1,0);
printf("%lld",ans);
return 0;
}
F
(已补)
我为什么会留一道水题
评定为中模拟一道
呃,建个优先队列保存点的距离,再建个dsu保存连通块就好
#include<bits/stdc++.h>
#define usetime() (double)clock () / CLOCKS_PER_SEC * 1000.0
#define abs(x) ((x)<0 ? -(x) : (x))
using namespace std;
typedef long long LL;
const int maxn=3005;
void read(int& x){
char c;
bool f=0;
while((c=getchar())<48) f|=(c==45);
x=c-48;
while((c=getchar())>47) x=x*10+c-48;
x=(f ? -x : x);
return;
}
struct edge{
int a,b;
LL dis;
edge(){ }
edge(int ai,int bi);
bool operator<(edge a)const;
};
int x[maxn],y[maxn];
int cnt=0;
edge::edge(int ai,int bi){
a=ai,b=bi,dis=abs(x[ai]-x[bi])+abs(y[ai]-y[bi]);
}
bool edge::operator<(edge a)const{
return dis>a.dis;
}
int f[maxn];
int find_f(int u){
if(f[u]==u) return u;
else return f[u]=find_f(f[u]);
}
void merge_f(int u,int v){
int x=find_f(u),y=find_f(v);
f[x]=y;
}
priority_queue<edge> q;
void add_dot(int xi,int yi){
++cnt;
x[cnt]=xi,y[cnt]=yi;
f[cnt]=cnt;
for(int i=1;i<cnt;i++){
q.push(edge(i,cnt));
}
}
LL merge_dot(){
while((!q.empty())&&(find_f(q.top().a)==find_f(q.top().b))){
q.pop();
}
if(q.empty()) return -1;
LL d=q.top().dis;
while((!q.empty())&&q.top().dis==d){
edge e=q.top();
q.pop();
if(find_f(e.a)==find_f(e.b)) continue;
merge_f(e.a,e.b);
}
return d;
}
int n,t;
int main(){
read(n),read(t);
int xi,yi;
for(int i=1;i<=n;i++){
read(xi),read(yi);
add_dot(xi,yi);
}
while(t--){
int op;
read(op);
if(op==1){
read(xi),read(yi);
add_dot(xi,yi);
}
else if(op==2){
printf("%lld\n",merge_dot());
}
else{
read(xi),read(yi);
if(find_f(xi)==find_f(yi)){
printf("Yes\n");
}
else{
printf("No\n");
}
}
}
return 0;
}
//^o^

浙公网安备 33010602011771号