Codeforces Round #499 (Div. 1)

https://codeforces.com/contest/1010

为啥我\(\rm Div.1\)能\(A4\)题还是\(\rm specialist....\)

A. Fly

二分答案,送分题。

#include<bits/stdc++.h>
using namespace std; void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
} void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double
#define ll long long #define pii pair<int,int >
#define vec vector<int > #define pb push_back
#define mp make_pair
#define fr first
#define sc second #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 2e5+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7; int a[maxn],b[maxn],n,m; int check(lf x) {
for(int i=1;i<=n-1;i++) {
x-=(x+m)/(lf)a[i];
x-=(x+m)/(lf)b[i+1];
if(x<0) return 0;
}x-=(x+m)/(lf)a[n];
x-=(x+m)/(lf)b[1];
if(x<0) return 0;
return 1;
} int main() {
read(n),read(m);
FOR(i,1,n) read(a[i]);
FOR(i,1,n) read(b[i]);
lf l=0,r=2e9;
while(r-l>1e-6) {
lf mid=(l+r)*0.5;
if(check(mid)) r=mid;
else l=mid;
}
if(l>1e9) puts("-1");
else printf("%.10lf\n",l);
return 0;
}

B. Rocket

简单的交互题。

第一轮先每次都问\(1\),问出这个位置是真还是假,然后二分答案就好了。

#include<bits/stdc++.h>
using namespace std; void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
} void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double
#define ll long long #define pii pair<int,int >
#define vec vector<int > #define pb push_back
#define mp make_pair
#define fr first
#define sc second #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 2e5+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7; int a[maxn],n,m; int main() {
read(n),read(m);
for(int i=1;i<=m;i++) {
puts("1");fflush(stdout);
read(a[i]);if(!a[i]) return 0;
}
int l=1,r=n;
for(int i=m+1;i<=60;i++) {
int mid=(l+r)>>1,x;
write(mid);fflush(stdout);read(x);
if(!x) return 0;
if(x==a[(i-1)%m+1]) l=mid+1;
else r=mid-1;
}
return 0;
}

C. Border

小凯的疑惑。

先把所有数求\(\gcd\),那么这就是我们可以凑出来的最小的非\(0\)数了,具体参见小凯的疑惑,两个互质的数\(a,b\)不可以凑出来的最小的数是\(ab-a-b\)。

#include<bits/stdc++.h>
using namespace std; void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
} void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double
#define ll long long #define pii pair<int,int >
#define vec vector<int > #define pb push_back
#define mp make_pair
#define fr first
#define sc second #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7; int a[maxn],n,m,c[maxn][2],f[maxn],g[maxn],op[maxn],vis[maxn]; int main() {
read(n),read(m);int t=m;
for(int i=1;i<=n;i++) read(a[i]),t=__gcd(t,a[i]);
int x=t;
while(!vis[x]) vis[x]=1,x=(x+t)%m;
int ans=0;
for(int i=0;i<m;i++) ans+=vis[i];write(ans);
for(int i=0;i<m;i++) if(vis[i]) printf("%d ",i);puts("");
return 0;
}

D. Mars rover

简单的\(\rm tree\ dp\),设\(f[i]\)表示\(i\)的子树传上来的数,\(g[i]\)表示\(i\)这个点的结果反转,忽视\(i\)的子树,\(1\)的结果。

那么直接深搜暴力更新就好了,先更新\(f\)在更新\(g\)。

#include<bits/stdc++.h>
using namespace std; void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
} void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double
#define ll long long #define pii pair<int,int >
#define vec vector<int > #define pb push_back
#define mp make_pair
#define fr first
#define sc second #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7; int a[maxn],n,m,c[maxn][2],f[maxn],g[maxn],op[maxn]; char s[5]; void dfs(int x) {
if(c[x][0]) dfs(c[x][0]);
if(c[x][1]) dfs(c[x][1]);
int a=f[c[x][0]],b=f[c[x][1]];
if(op[x]==1) f[x]=a&b;
else if(op[x]==2) f[x]=a|b;
else if(op[x]==3) f[x]=a^b;
else if(op[x]==4) f[x]=!a;
} void dp(int x,int fa,int e) {
if(x!=1) {
int o=op[fa];
if(o==1) {
if((f[e]&(!f[x]))!=f[fa]) g[x]=g[fa];
else g[x]=f[1];
} else if(o==2) {
if((f[e]|(!f[x]))!=f[fa]) g[x]=g[fa];
else g[x]=f[1];
} else if(o==3) {
if((f[e]^(!f[x]))!=f[fa]) g[x]=g[fa];
else g[x]=f[1];
} else if(o==4) g[x]=g[fa];
}
if(c[x][0]) dp(c[x][0],x,c[x][1]);
if(c[x][1]) dp(c[x][1],x,c[x][0]);
} int main() {
read(n);
for(int i=1;i<=n;i++) {
scanf("%s",s+1);
if(s[1]=='A') op[i]=1;
else if(s[1]=='O') op[i]=2;
else if(s[1]=='X') op[i]=3;
else if(s[1]=='N') op[i]=4;
else op[i]=5;
if(op[i]<=3) read(c[i][0]),read(c[i][1]);
else if(op[i]==4) read(c[i][0]);
else read(f[i]);
}
dfs(1);
g[1]=!f[1];
dp(1,0,0);
for(int i=1;i<=n;i++) if(op[i]==5) putchar(g[i]+'0');
return 0;
}

E. Store

\(\rm kd\ tree\),不想写先咕着...

F. Tree

这是一道毒瘤题。

由于这题非常巧妙而且非常毒瘤我就新开了一篇来写。

题解看这里:Codeforces Round #499 (Div. 1) F. Tree

这里扔个代码把:

#include<bits/stdc++.h>
using namespace std; void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
} void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double
#define ll long long #define pii pair<int,int >
#define vec vector<int > #define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define _sz(x) ((int)x.size()) #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 1<<19|10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 998244353; int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
int del(int x,int y) {return x-y<0?x-y+mod:x-y;}
int mul(int x,int y) {return 1ll*x*y-1ll*x*y/mod*mod;} int qpow(int a,int x) {
int res=1;
for(;x;x>>=1,a=mul(a,a)) if(x&1) res=mul(res,a);
return res;
} namespace poly {
int N,w[maxn],pos[maxn],bit,mxn,t[2][maxn]; void init(int l) {
for(mxn=1;mxn<=l;mxn<<=1) ;
w[0]=1,w[1]=qpow(3,(mod-1)/mxn);
for(int i=2;i<=mxn;i++) w[i]=mul(w[i-1],w[1]);
} void ntt(int *r,int op) {
FOR(i,1,N-1) if(pos[i]>i) swap(r[pos[i]],r[i]);
for(int i=1,d=mxn>>1;i<N;i<<=1,d>>=1)
for(int j=0;j<N;j+=i<<1)
for(int k=0;k<i;k++) {
int x=r[j+k],y=mul(r[i+j+k],w[k*d]);
r[j+k]=add(x,y),r[i+j+k]=del(x,y);
}
if(op==-1) {
reverse(r+1,r+N);int d=qpow(N,mod-2);
for(int i=0;i<N;i++) r[i]=mul(r[i],d);
}
} vec pmul(vec a,vec b) {
if(1ll*_sz(a)*_sz(b)<=5000) {
vec c;c.resize(_sz(a)+_sz(b)-1);
FOR(i,0,_sz(a)-1) FOR(j,0,_sz(b)-1) c[i+j]=add(c[i+j],mul(a[i],b[j]));
return c;
}
for(N=1,bit=0;N<_sz(a)+_sz(b);N<<=1,bit++);
FOR(i,0,N-1) pos[i]=pos[i>>1]>>1|((i&1)<<(bit-1));
FOR(i,0,_sz(a)-1) t[0][i]=a[i];FOR(i,_sz(a),N) t[0][i]=0;
FOR(i,0,_sz(b)-1) t[1][i]=b[i];FOR(i,_sz(b),N) t[1][i]=0;
ntt(t[0],1),ntt(t[1],1);
FOR(i,0,N-1) t[0][i]=mul(t[0][i],t[1][i]);
ntt(t[0],-1);vec c;
FOR(i,0,_sz(a)+_sz(b)-1) c.pb(t[0][i]);
return c;
} vec padd(vec a,vec b) {
if(_sz(a)>_sz(b)) {FOR(i,0,_sz(b)-1) a[i]=add(a[i],b[i]);return a;}
FOR(i,0,_sz(a)-1) b[i]=add(a[i],b[i]);return b;
}
} ll k;
int n,ch[maxn],head[maxn],tot,sz[maxn],F[maxn],cnt;
struct edge{int to,nxt;}e[maxn<<1]; vec f[maxn],r[maxn]; void ins(int u,int v) {e[++tot]=(edge){v,head[u]},head[u]=tot;} void dfs(int x,int fa) {
sz[x]=1;F[x]=fa;
for(int i=head[x],v;i;i=e[i].nxt)
if((v=e[i].to)!=fa) {dfs(v,x);sz[x]+=sz[v];if(sz[ch[x]]<sz[v]) ch[x]=v;}
} void solve(int lt,int rt,vec &a,vec &b) {
if(lt==rt) return a=b=r[lt],void();
vec al,ar,bl,br;int mid=(lt+rt)>>1;solve(lt,mid,al,bl),solve(mid+1,rt,ar,br);
b=poly::pmul(bl,br);a=poly::padd(poly::pmul(ar,bl),al);
} vec dfs2(int x) {
for(int t=x;t;t=ch[t]) {
for(int i=head[t];i;i=e[i].nxt) if(e[i].to!=F[t]&&e[i].to!=ch[t]) f[t]=dfs2(e[i].to);
if(_sz(f[t])<1) f[t].resize(1);f[t][0]++;
f[t].insert(f[t].begin(),0);
}
cnt=0;for(int t=x;t;t=ch[t]) r[++cnt]=f[t];
vec a,b;solve(1,cnt,a,b);return a;
} int main() {
read(n),scanf("%lld",&k);poly::init(n<<1);k%=mod;
for(int i=1,x,y;i<n;i++) read(x),read(y),ins(x,y),ins(y,x);
dfs(1,0);vec res=dfs2(1);int t=1,ans=0;
for(int i=1;i<_sz(res);i++) {
ans=add(ans,mul(res[i],t));
t=mul(t,mul((k+i)%mod,qpow(i,mod-2)));
}write(ans);
return 0;
}

Codeforces Round #499 (Div. 1)的更多相关文章

  1. Codeforces Round #499 (Div. 2)

    Codeforces Round #499 (Div. 2) https://codeforces.com/contest/1011 A #include <bits/stdc++.h> ...

  2. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  3. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  4. 7-27 Codeforces Round #499 (Div. 2)

    C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search .math. 题意:总 ...

  5. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  6. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  7. Codeforces Round #499 (Div. 2) Problem-A-Stages(水题纠错)

    CF链接  http://codeforces.com/contest/1011/problem/A Natasha is going to fly to Mars. She needs to bui ...

  8. Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)

    C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  9. Codeforces Round #499 (Div. 2)(1011)

    Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide fo ...

随机推荐

  1. 如何理解 Web API

    什么是web API? web API 控制器.路由 测试  Web  API  什么是web API ? 简单说,API是接口,访问程序的某一个功能或者数据,实现移动端和客户端的程序之间的数据交互: ...

  2. Flask纪要

    flask学习过程 1框架基础 2redis高性能key-value数据库 3视图具有装饰器的路由函数 4模板html文件 面向对象操作数据库orm 5蓝图 6单元测试 7GitHub 8项目 学习的 ...

  3. WordPress入门 之 设置导航菜单

    WordPress 3.0 添加了一个自定义导航菜单的功能,让你可以很自由地设置网站的导航菜单.现在大多数的主题也都支持这个功能了,那么,究竟该如何设置WordPress导航菜单?今天倡萌就介绍一下. ...

  4. C++11原子操作与无锁编程(转)

    不讲语言特性,只从工程角度出发,个人觉得C++标准委员会在C++11中对多线程库的引入是有史以来做得最人道的一件事:今天我将就C++11多线程中的atomic原子操作展开讨论:比较互斥锁,自旋锁(sp ...

  5. 推荐一个web字体转换工具TTF转SVG

    推荐一个web字体转换工具:https://www.fontsquirrel.com/tools/webfont-generator

  6. arcpy地理处理工具案例教程-景观形状指数计算

    arcpy地理处理工具案例教程-景观形状指数计算 商务合作,科技咨询,版权转让:向日葵,135-4855_4328,xiexiaokui#qq.com 使用方法:输入要素类即可,其余参数均默认. 商务 ...

  7. IIS连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解

    IIS:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池的最大工作进程数详解 iis性能指标的各种概念:连接数.并发连接数.最大并发工作线程数.应用程序池的队列长度.应用程序池 ...

  8. Hadoop的三种调度器FIFO、Capacity Scheduler、Fair Scheduler(转载)

    目前Hadoop有三种比较流行的资源调度器:FIFO .Capacity Scheduler.Fair Scheduler.目前Hadoop2.7默认使用的是Capacity Scheduler容量调 ...

  9. 领域模型/DDD领域驱动设计

    http://www.fanyilun.me/2018/04/08/%E8%B0%88%E8%B0%88%E9%A2%86%E5%9F%9F%E5%BB%BA%E6%A8%A1/ http://www ...

  10. 【Docker学习之六】Docker容器互联

    环境 docker-ce-19.03.1-3.el7.x86_64 centos 7 一.基于Volume的互联就是-v参数,将本机文件或目录挂载到容器目录,实现文件目录共享 二.基于Link的互联 ...