1004
找规律:
答案为m*n/m^n
由于数据较大,而且涉及到gcd,因此用java比较好
import java.math.*;
import java.util.Scanner;
import java.io.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin =new Scanner (System.in);
while(cin.hasNextInt())
{
int n,t=cin.nextInt();
BigInteger m,x,y,z,GCD;
while((t--)>0)
{
m=cin.nextBigInteger();
n=cin.nextInt();
y=m.pow(n);
z=BigInteger.valueOf(n);
x=m.multiply(z);
GCD=x.gcd(y);
System.out.println(x.divide(GCD)+"/"+y.divide(GCD));
}
}
}
}
1005 字符串
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 1000005
int next[N];
int ans[N];
void solve(char *s,int size)
{
int res=0;
int i,j;
next[0]=j=0;
for(i=1; i<size; ++i)
{
while(j>0&&s[i]!=s[j])j=next[j-1];
if(s[i]==s[j])++j;
next[i]=j;
if(i<size-1)
{
if(i+1>=2*j)ans[i]=j;
else
{
int J=j;
while(i<2*J)
{
J=next[J-1];
}
ans[i]=J;
}
}
else
{
for(int k=1; k<size; ++k)
{
int J=j;
while(size-J<k)
{
J=next[J-1];
}
res=max(res,min(J,ans[k]));
//printf("%d ",ans[i]);
}
}
}
printf("%d\n",res);
}
char s[N];
int main()
{
//freopen("G:\\in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",s);
solve(s,strlen(s));
}
return 0;
}
1006:签到题
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
//freopen("G:\\in.txt","r",stdin);
int n,k;
while(~scanf("%d%d",&n,&k)&&(n||k))
{
if((n-1)%(k+1)==0)puts("Jiang");
else puts("Tang");
}
return 0;
}
1010:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define lint long long
#define N 20010
int a[N][3];
int n;
bool ok(lint k)
{
lint sum=0,tmp;
for(int i=0;i<n;++i)
{
tmp=min(k,(lint)a[i][1]);
if(tmp>=a[i][0])sum+=((tmp-a[i][0])/a[i][2]+1);
}
return sum%2;
}
void solve()
{
lint L=-1,R=((lint)(1))<<32,mid;
lint TR=R;
//if(TR==R)printf("OK");
while(L<R-1)
{
mid=(L+R)>>1;
if(ok(mid))R=mid;
else L=mid;
}
if(R==TR)puts("DC Qiang is unhappy.");
else
{
lint ans=0;
for(int i=0;i<n;++i)
if(R>=a[i][0]&&R<=a[i][1]&&!((R-a[i][0])%a[i][2]))++ans;
printf("%I64d %I64d\n",R,ans);
}
}
int main()
{
//freopen("G:\\in.txt","r",stdin);
while(~scanf("%d",&n))
{
for(int i=0;i<n;++i)scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
solve();
}
return 0;
}