杭电acm1405-2200

更新时间:2024-06-22 05:48:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1405:

#include #include

#define MAXLEN 65536 using namespace std; int main(){

int n,ni,a[MAXLEN],hash[MAXLEN],k,ki,i,cas=0; while(scanf(\ cas++;//记录实例数量

if(cas>1)//第一次不输出回车 putchar('\\n');

printf(\

k=0;

memset(a,0,sizeof(a));

memset(hash,0,sizeof(hash));

while(n!=1){//如果n!=1表示还未把所有的因子取出 for(ni=2;ni<=n&&n%ni!=0;ni++) ; a[k++]=ni; n/=ni; }

for(ki=0;ki

for(i=2;i0;i++)//输出对应的因子与因子的数量 if(hash[i]!=0){

k-=hash[i];//减少相应的数量hash[i] printf(\ }

putchar('\\n'); }

return 0; }

1406:

#include #include int a[10001]; int main() {

int i, sum, T, j, count, num1, num2, temp;

memset(a, 0, sizeof(a)); for(i=2;i<=10000;i++) {

sum = 0;

for(j=1;j<=i/2;j++) {

if(i%j==0) sum+=j; }

if(sum==i) a[i]=1; }

scanf(\ while(T--) {

count=0;

scanf(\ if(num1>num2) {

temp=num1; num1=num2; num2=temp; }

for(i=num1;i<=num2;i++) {

if(a[i]==1) count++; }

printf(\ }

return 0; }

1407:穷举

#include #include void main() {

long x,y,z,num; int i,j,k;

while(scanf(\ {

for(i=1;i<=sqrt(num);i++) {

for(j=i;j<=sqrt(num);j++) {

for(k=j;k<=sqrt(num);k++) {

if(i*i+j*j+k*k==num) {

printf(\ goto end; } } } } end:; } }

1408:

#include #include #define eps 1e-8 using namespace std; int main() {

double d,vul; int k,t;

while(scanf(\ {

k=1;t=0;

while(vul-k*d>eps) {//滴完为止 t+=k+1; vul-=k*d; k++; }

if(vul-int(vul/d)*d

return 0; }

1412:

#include #include #define N 10000

int cmp(const void *a,const void *b) {

return *(int *)a-*(int *)b; }

int main() {

int num1,num2,a[N],b[N],i,k,j,c[20000];

while(scanf(\ {

for(i=0;i

qsort(a,num1,sizeof(a[0]),cmp); qsort(b,num2,sizeof(b[0]),cmp); i=0,j=0,k=0;

for(;i

if(a[i]

c[k]=a[i++]; else

if(a[i]>b[j])

c[k]=b[j++]; else {

i++; k--; } }

if(i

while(i

c[k++]=a[i++]; if(j

while(j

c[k++]=b[j++]; for(i=0;i

return 0; }

1418:

#include #include using namespace std; int main()

{//采用欧拉定理f+v-e=2

unsigned int n,m;//n是点,m是面,求的是边 while(scanf(\ {

printf(\ }

return 0; }

1420:

#include int main() {

__int64 a, i, b, c, sets, temp ; scanf(\ while( sets-- ) {

scanf(\ temp=a;

for(i=1;i

a*=temp; a%=c; }

a%=c; if(c==1) {

printf(\ continue; }

printf(\ } return 0; }

1465:

#include int main()

{

a[num][s1[j]-97]++; }

len=strlen(s2); num++;

for(j=0;j

a[num][s2[j]-97]++; }

for(p=2;p<=k;p++) {

for(j=0;j<26;j++) {

a[p][j]=a[p-1][j]+a[p-2][j]; } }

for(j=0;j<26;j++)

printf(\ printf(\ }

return 0; }

1718:

#include

int a[100]; //下标为分数,值为标记; void main() {

int no,n,s,i,cnt,key;

while (scanf(\ {

for (i=0;i<=100;i++) {

a[i]=0; //恢复状态; }

while (scanf(\ {

if(n==0&&s==0) break;

if (n == no) //当学号相等时标记-1,否则标记为1; {

key=s; a[s]++; }

else

a[s]++; }

cnt=0;

for (i=100;i>=0;i--) {

if (a[i]!=0) //从100往下找; {

cnt+=a[i];

if (i==key) //找到,退出; {

break; } } }

printf(\ } }

1720:

#include main() {

int x,y;

while(scanf(\ { printf(\ }

return 0; }

1799:

#include int a[2001][2001]; void main() {

int i,j,t,m,n;

for(i=0;i<2001;i++) { a[i][0]=a[i][i]=1; for(j=1;j

a[i][j]=(a[i-1][j-1]+a[i-1][j])07;// 杨辉三角打表 }

scanf(\

while(t--) { scanf(\ printf(\ } }

1859:

#include int main() { int a,b,i,j,minx,miny,maxx,maxy; while(scanf(\ { if(a==0&&b==0) break; minx=maxx=a; miny=maxy=b; for(i=1;;i++) { scanf(\ if(a==0&&b==0) break; if(amaxx) maxx=a; if(bmaxy) maxy=b; } printf(\ }

return 0; }

1862:

#include #include #include struct student { char num[10]; char name[10]; int score; }

stu[100010];

int cmp1(const void *a,const void *b)

{ struct student *c=(struct student *)a; struct student *d=(struct student *)b; return strcmp(c->num,d->num); }

int cmp2(const void *a,const void *b) { struct student *c=(struct student *)a; struct student *d=(struct student *)b; if(strcmp(c->name,d->name)) return strcmp(c->name,d->name); else return strcmp(c->num,d->num); }

int cmp3(const void *a,const void *b) { struct student *c=(struct student *)a; struct student *d=(struct student *)b; if(c->score!=d->score) return c->score-d->score; else return strcmp(c->num,d->num); }

int main() { int i,m,n,k=1;

while(scanf(\ { for(i=0;i

1877:

#include

#include int main() { int m,a,b; char k[100]; while(scanf(\ { scanf(\ itoa(a+b,k,m); printf(\ } return 0; }

1898:

#include int main() {

int a,b,t,n;

scanf(\ while(n--) {

scanf(\ if(t%a==t%b)

printf(\ else {

if(t%a

printf(\ else

printf(\ } }

return 0; }

1976:

#include main() {

int a1,a2,a3,b1,b2,b3,i,n;

while(scanf(\ {

for(i=0;i

{

scanf(\ if(a1>b1)printf(\

else if(a1b2)printf(\ else if(a2b3)printf(\ else if(a3

1977:

#include using namespace std; int main() {

int t;

__int64 n; cin>>t; while(t--) {

scanf(\

printf(\ }

return 1; }

1985:

#include \#include \

double change(double dit,int kind) {

if(kind==1) return dit*2.2046;

else if (kind==2) return dit*0.4536; else if (kind==3) return dit*0.2642; else if (kind==4) return dit*3.7854; }

int main() {

int n,i; double m; char str[15];

scanf(\ for(i=0;i

scanf(\ printf(\ if (strcmp(str,\ printf(\ else if (strcmp(str,\ printf(\ else if (strcmp(str,\ printf(\ else if (strcmp(str,\

printf(\ }

return 0; }

2101:

#include int main() { int m,n; while(scanf(\ { if((m+n)?) puts(\ else puts(\ } }

2103:

? ? ? ? ? ? ? ? ?

#include #include using namespace std; int main()

{long long t,n,m,i,b;

long long a[32],ans; //注意用long long cin>>t; while(t--) {cin>>n>>m;

?? for(i=1;i<=m;i++) ?? cin>>a[i]; ?? b=n;

?? for(i=1;i<=m;i++)

?? {if(a[i]==1&&i

?? ans=(int)(pow(2.0,1.0*(m-b))-1);

?? if(ans!=0)cout<

?? return 0; ?? } ??

思路是这样的,现将b初始化在刚好要超生的边缘,

如果生男孩是在超生范围之内的话,那么交的罚金将从那个那还开始,

反之从边缘的那个数到最后的数刚好那个之和(代码中的n,m与题目的表示恰好调换了) 注意:这道题的测试数据,可以是计划生育的孩子总数就是为0,还有对生很多儿子时,要在读到第一个儿子之后就要开始处罚了,所以b的值就不变了。。。

2106:

#include #include using namespace std; int main() {

int n,a[201],b[201],i,j,k; __int64 m; while(cin>>n) { m=0; for(i=0;i=10) { while(a[i]>0)

}

{ j=a[i]; a[i]=a[i]/10; m+=(j*pow(b[i],k)); k++; } } if(a[i]<10) m+=a[i]; } printf(\}

return 0;

2107:

#include main() {

int n,x,max;

while(scanf(\ {

max=0; while(n--) {

scanf(\ if(max

printf(\ } }

2109:

#include int main(void) { int N,i,index1,index2,tempe1,tempe2,k,j,m; int sum1,sum2,sum3,p,q; int a[100],b[100]; while(scanf(\ { if(N==0) break; for(i=0;i

}

scanf(\ for(i=0;i

return 0;

2113:

#include int main() {

int n,sum,flag=0;

while (scanf(\ {

sum=0; while (n) { if (n%2==0) sum+=n; n/=10; }

if(flag) printf(\ flag=1;

printf(\ }

return 0; }

2114:

#include int main(void) {

long long n;

while (scanf(\ {

n%=10000; n=n*(n+1)/2;

printf(\ }

return 0; }

2115:

#include #include #include struct _stu {

char name[80]; int score; };

int namecmp(const void*a, const void*b); int scorecmp(const void*,const void*); int main(void)

{

struct _stu arr[11];

int m,s,count,t,begin,len,prev,rank,tag=0,counter=1; while(scanf(\ {

for(count=0;count

scanf(\ arr[count].score=m*100+s; }

qsort(arr,t,sizeof(arr[0]),scorecmp); begin=0; len=1;

prev=arr[0].score; while(begin+len

if(arr[len+begin].score==prev) {

len++; } else {

qsort(arr+begin,len,sizeof(arr[0]),namecmp); begin=begin+len+1; len=1;

if(begin>=t) {

break; }

prev=arr[begin].score; } }

if(len>1) {

qsort(arr+begin,len,sizeof(arr[0]),namecmp); }

prev=arr[0].score; rank=1; if(tag)

printf(\ else

tag=1;

printf(\ for(count=1;count<=t;count++)

{

if(arr[count-1].score!=prev) {

rank=count;

prev=arr[count-1].score; }

printf(\ } } }

int scorecmp(const void*a,const void*b) {

if( (*(struct _stu*)a).score > (*(struct _stu*)b).score) return 1; else

return -1; }

int namecmp(const void*a, const void*b) {

return (strcmp((*(struct _stu*)a).name,(*(struct _stu*)b).name))*(1); }

2123:

#include int main() {

int n,m,i,j;

scanf(\ while(n--) {

scanf(\ for(i=1;i<=m;i++) {

for(j=1;j<=m;j++) {

if(j!=1) printf(\ printf(\ }

printf(\ } } }

2131:

#include using namespace std;

void main() {

int n;

char c,ch[200]={0}; while(cin>>c>>ch) {

n=0;

c=tolower(c);

for(int i=0; i

if( c==tolower(ch[i]) ) {

n++; } }

printf(\ memset(ch,0,200); } }

2132:

#include #include int main() { __int64 i,n, sum[100001]; sum[0]=0; sum[1]=1; sum[2]=3; sum[3]=30; for(i=4;i<=100000;i++) {

if(i%3==0)

sum[i] = sum[i-1] +i*i*i; else

sum[i] = sum[i-1] + i; }

while(scanf(\ {

printf(\ } return 0; }

2133:

#include int f(int year) { if(year%4==0 && year0!=0 || year@0==0) return 1; else return 0; }

int _Date2Week(int year,int month,int day) { if(month==1||month==2) { year -=1; month +=12; } return (day+1+2*month+3*(month+1)/5+year+(year/4)-year/100+year/400)%7; }

int main() { int zun[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; int izun[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int year,month,day; int week; char

w[7][10]={\ while(scanf(\ { if(month<1 || month >12 || day<1 || day>31) printf(\ else { if(f(year)==1) {

if(month==2 && day>29) printf(\ else if(month!=2 && day>31 &&(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)) printf(\ else if(month!=2 && day>30 &&(month==4 || month==6 || month==9 || month==11)) printf(\ else { week=_Date2Week(year,month,day); printf(\ } } else { if(month==2 && day>28) printf(\ else if(month!=2 && day>31 &&(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)) printf(\ else if(month!=2 && day>30 &&(month==4 || month==6 || month==9 || month==11)) printf(\ else { week=_Date2Week(year,month,day); printf(\ } } } } return 0; }

2134:

#include #include

int main()

{ }

double r1,r2,r,s2,s,temp; double PI=3.14159;

scanf(\while(r!=0) { s=PI*r*r; temp=s/3; r2=sqrt(temp/PI); s2=s-PI*r2*r2; r1=sqrt(s2/PI); printf(\ scanf(\}

return 0;

2135:

#include int main() { char data[11][11],x[11][11]; int i,j; int n,m; while(scanf(\ { for(i=0;i

}

}

} }

if(m==1) { for(i=0;i

if(m==2) { for(i=0;i

for(i=0;i

2136:

#include #include #include int a[1000001]; int b[1000001]; int main() {

int t; long n,i,j;

a[1]=0;

for(i=2; i<=1000000;i++) {

a[i]=1; }

for(i=2;i<=sqrt(1000000);i++) {

if(a[i]!=0) {

for(j=i*2;j<=1000000; j=j+i) {

if(a[j]!=0&&a[j]%a[i]==0) {

a[j]=0; } else

NULL; } } } t=1;

memset(b,0,sizeof(b)); for(i=2;i<=1000000;i++) {

if(a[i]==1) {

b[i]=t; t++; } }

for(i=2;i<=1000000/2;i++) {

if(a[i]==1) {

for(j=2*i;j<=1000000;j=j+i) b[j]=b[i]; } }

while(scanf(\ {

if(n==1)

printf(\ else {

printf(\ } }

return 0; }

2137:

#include #include int main() { int n; char c[100]; char x[100000]; unsigned int i,j; int f; while(scanf(\ { n=0; f=0; n=x[0]-48; if(strlen(x)>1) { for(i=1;i

{ n=(n+(x[i]-48))%8; f=0; i++; } } } else n=n%8;

if(n==0) { printf(\}

if(n==1) { for(i=strlen(c);i>=1;i--) { for(j=i-1;j>=1;j--) printf(\ printf(\ } }

if(n==2) { for(i=strlen(c);i>=1;i--) { for(j=strlen(c)/2;j>=1;j--) printf(\ printf(\ } }

if(n==3) { for(i=strlen(c);i>=1;i--) { for(j=strlen(c)-i;j>=1;j--) printf(\ printf(\ }

}

}

}

if(n==4) { for(i=strlen(c);i>=1;i--) printf(\ printf(\}

if(n==5) { for(i=strlen(c);i>=1;i--) { for(j=i-1;j>=1;j--) printf(\ printf(\ } }

if(n==6) { for(i=1;i<=strlen(c);i++) { for(j=0;j

if(n==7) { for(i=strlen(c);i>=1;i--) { for(j=strlen(c)-i;j>=1;j--) printf(\ printf(\ } }

return 0;

2138:

#include #include int iSqrt,i;

int isPrimeNum(long num) {

if (num<=2) {

return num==2; }

if (num%2==0) {

return 0; }

iSqrt=sqrt(num);

for(i=3;i<=iSqrt;i+=2) {

if (num%i==0) {

return 0; } }

return 1; }

int main() { int i,n,t; long x; while(scanf(\ { t=0; for(i=0;i

2139:

#include int main() { __int64 k,sum; int n;

while(scanf(\

{

k=(n+1)/2;

sum=(4*k*k*k-k)/3; printf(\ }

return 0; }

2143:

#include

__int64 pass(__int64 a,__int64 b,__int64 c) {

if(a==b+c) return 1;

else if(c!=0&&a==b%c) return 1;

else if(a==b*c) return 1; return 0; }

int main(void) {

__int64 a,b,c; int flag;

while(scanf(\ {

flag=0;

if(pass(a,b,c)==1) flag++;

if(pass(a,c,b)==1) flag++;

if(pass(b,a,c)==1) flag++;

if(pass(b,c,a)==1) flag++;

if(pass(c,a,b)==1) flag++;

if(pass(c,b,a)==1) flag++; if(flag!=0)

printf(\ else

printf(\

}

return 0; } 2148:

#include #include int main() {

int z, n, k, i, r, a[101]; scanf(\ while (z--) {

scanf(\ for (i=1; i<=n; i++) scanf(\ r = 0;

for (i=1; i<=n; i++) r+=a[i]>a[k]; printf(\ }

return 0; }

2153:

#include #include #include int main() {

int a,b,i,j,n;

while(scanf(\ {

if(n==1) {

printf(\ 1\\n\ continue; }

b=4*(n-1);

for(i=1,a=1;i

printf(\ %d\ else

printf(\ if(a<=9)

printf(\ %d\\n\ else

printf(\

for(j=0;j

if(b<=9)

printf(\ %d\ else

printf(\ for(i=0;i<3*n-6;i++) printf(\ if(a<=9)

printf(\ %d\\n\ else

printf(\ }

for(i=0;i

printf(\ %d\ else

printf(\ if(a<=9)

printf(\ %d\\n\ else

printf(\ }

return 0; }

2156:

#include

#define MAXN 110000 double a[MAXN];

int main() {

int n,i,x;

double ans,mul; a[1]=1;

for(i=2;i

a[i]=1/(double)i; }

while(scanf(\ {

ans=0; mul=1; x=2;

for(i=n-1;i>0&&x

ans+=i*a[x++]; }

ans=ans*2+(double)n; printf(\ }

return 0; }

2161:

#include #include bool prime[16010]; void list() {

memset(prime,true,sizeof(prime)); int i,j;

for(i=2;i<=16000;i++) if(prime[i])

for(j=i*2;j<=16000;j+=i) prime[j]=false; prime[1]=prime[2]=false; }

int main() {

list(); int n,a=1;

while(scanf(\ {

printf(\

puts(prime[n]?\ }

return 0; }

2162:

#include int main()

{

int n,i,a,sum,t=1;

while(scanf(\ {

if(n<=0)break; sum=0;

for(i=0;i

scanf(\ sum+=a; }

printf(\ t++; }

return 0; }

2164:

#include void main() { int x,y,t,n; char p[3]; scanf(\ while(t--) { scanf(\ x=0;y=0; while(n--) { gets(p); if((p[0]=='R')&&(p[2]=='P')) y++; if((p[0]=='R')&&(p[2]=='S')) x++; if((p[0]=='P')&&(p[2]=='R')) x++; if((p[0]=='P')&&(p[2]=='S')) y++; if((p[0]=='S')&&(p[2]=='R')) y++; if((p[0]=='S')&&(p[2]=='P')) x++; }

}

}

if(x==y) printf(\if(x>y) printf(\if(x

2178:

#include int main(void) {

int T,n,i; __int64 m;

scanf(\ while(T--) {

scanf(\ m=1; for(i=0;i

printf(\ } }

2186:

#include main() {

int n,a,b,c,sum,m,x,y,z; scanf(\ while(m--) {

scanf(\ sum=0; a=n/2; b=(n-a)*2/3; c=n-a-b; x=a/10+(a>=1?1:0); y=b/10+(b>=1?1:0); z=c/10+(c>=1?1:0); sum+=x+y+z; printf(\ } } 2200:

#include using namespace std; #define max 60 __int64 f[max+10]; __int64 pow(int n) {

__int64 i,sum=1; for(i=1;i<=n;i++) sum*=2; return sum; }

int main() {

__int64 n,i; f[1]=1;f[2]=1;

for(i=3;i

while(scanf(\ { printf(\ }

return 0; }

本文来源:https://www.bwwdw.com/article/j7h3.html

Top