t1 5 pts
t2 70 pts
t4 60pts
t1 整数校验器
#include<bits/stdc++.h>
using namespace std;
long long l,r,t,len,wei;
unsigned long long x;
char s[25];
int main()
{
scanf("%lld%lld%lld",&l,&r,&t);
while(t--)
{
x=0;
scanf("%s",s);
len=strlen(s);
if(s[0]=='0')
{
if(len==1)
printf("0
");
else
printf("1
");
}
else if(s[0]=='-')
{
if(len==1)
printf("1
");
else if(s[1]=='0')
printf("1
");
else if(len>20)//超出long long 范围内,long long 最高19位,但有一位负号所以要>20
printf("2
");
else //字符串转为数操作
{
wei=1;
while(wei<len)
{
x=x*10+(int)s[wei]-'0';
wei++;
}
x=-x;/////////////////////////////////////////坑死我了
if(x>=l)
printf("0
");
else
printf("2
");
}
}
else //处理正数同上
{
if(len>19)
printf("2
");
else
{
wei=0;
while(wei<len)
{
x=x*10+(int)s[wei]-'0';
wei++;
}
if(x<=r)
printf("0
");
else
printf("2
");
}
}
}
return 0;
}
t2P5239 回忆京都
神犇代码
#include<bits/stdc++.h>
#define N 1005
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int ans[N][N],q,n,m;
int main()
{
rep(i,1,1000)
rep(j,1,1000)
ans[i][j]=(ans[i-1][j-1]+ans[i-1][j]+i)%19260817;
scanf("%d",&q);
while(q--)
{
scanf("%d%d",&n,&m);
printf("%d
",ans[m][n]);
}
return 0;
}
我的考场代码
*#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define mod 19260817
#define N 2010
#define ll long long
using namespace std;
int read()
{
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
}
int t,k,n,m;
ll C[N][N],s[N][N];//C[i][j]:i角标,j上标
int main()
{
//freopen("input.txt","r",stdin);
t=read();
rep(i,0,2000)
C[i][i]=C[i][0]=1;
rep(i,1,2000)
rep(j,1,i-1)
{
if(j>i)C[i][j]=0;
C[i][j]=(C[i-1][j]%mod+C[i-1][j-1]%mod)%mod;
}
while(t--)
{
ll ans=0;
n=read(),m=read();
rep(i,1,m)
rep(j,1,n)
{
if(j>i)continue;
ans+=C[i][j]%mod;
}
printf("%lld
",ans%mod);
}
return 0;
为什么只有70 pts并tle了呢?
因为要用二位前缀和来加速!!!!!!!!!!!!
附上AC代码
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define mod 19260817
#define N 2010
#define ll long long
using namespace std;
int read()
{
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
}
int t,k,n,m;
ll C[N][N],sum[N][N];//C[i][j]:i角标,j上标
int main()
{
//freopen("input.txt","r",stdin);
C[1][1]=C[1][0]=1;
rep(i,2,1005)
{
C[i][0]=1;
rep(j,1,i)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
rep(i,1,1005)
rep(j,1,1005)
sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+C[i][j]+mod)%mod;
t=read();
while (t--)
{
int m=read(),n=read();
printf("%d
",sum[n][m]);
}
return 0;
}