FOI冬令营 Day4
T1、循环流(flow)
传送门
Code
/*
特判就完事了
2019/2/15
*/
#include<bits/stdc++.h>
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
int ans;
int main()
{
freopen("flow.in","r",stdin);
freopen("flow.out","w",stdout);
int test=read();
int T=read();
while(T--)
{
int n=read(),a=read(),b=read();
if(n==2)
{
if(a==0){if(b%2==1||b==0) puts("0");else puts("1"),++ans;}
else{if(a%2==1) puts("0");else puts("1"),++ans;}
continue;
}
bool flag=0;
for(int i=0;i<=a;i+=2)
{
if(flag) break;
int A=a-i,B=b+i/2;
if(A==0||B==0) if(A+B<n) continue;
if(A==1) continue;
if(A>n*(n-1)) continue;
if((A>0&&B>0)&&A+B<n+1) continue;
flag=1;puts("1");++ans;break;
}
if(!flag) puts("0");
}
return 0;
}
T2、整除分块(mex)
传送门
Code
//2019/2/15
//37pts
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define N 20000000
int V[N+5],last=1;
int val(int n)
{
if(last>1) if((n/(last-1))==(n/last)) return --last;
for(;;++last) if((n/last)==(n/(last+1))) return last;
}
int test,T,l,r;
int main()
{
freopen("mex.in","r",stdin);
freopen("mex.out","w",stdout);
scanf("%d",&test);
for(int i=1;i<=N;++i) V[i]=val(i);
for(int i=1;i<=N;++i) V[i]=(V[i]+V[i-1])%mod;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&l,&r);
printf("%d\n",(V[r]-V[l-1]+mod)%mod);
}
return 0;
}
满分做法?咕咕咕
T3、森林(forest)
传送门
Code
咕咕咕
Blog来自PaperCloud,未经允许,请勿转载,TKS!
致虚极,守静笃,万物并作,吾以观其复