HPUACM Freshman Exercises Round 1 [标程]

来源:互联网 发布:redis hash key mysql 编辑:程序博客网 时间:2024/06/06 05:32

A

#include <stdio.h>int main(){    int a, b, k;    while(scanf("%d%d%d", &a, &b, &k) != EOF) {        printf("%.8lf\n", (double)a / (a + b));    }    return 0;}

B

#include <cstdio>int main() {    int n;    while(scanf("%d", &n) != EOF) {        if(n % 4 == 0) puts("YES");        else puts("NO");    }    return 0;}

C

#include <cstdio>#include <cmath>typedef long long LL;const int MAXN = 100000 + 10;LL dp[MAXN];void init() {    for(int i = 1; i <= 100000 + 5; i++) {        LL ans = 0;        for(int j = 1; j <= sqrt(i); j++) {            if(i % j == 0) {                ans = ans + i / j + j;                if(j * j == i) ans -= j;            }         }        dp[i] += ans + dp[i - 1];    }} int main() {    int T, L, R;    init();    scanf("%d", &T);    while(T--) {        scanf("%d %d", &L, &R);        printf("%lld\n", dp[R] - dp[L - 1]);    }    return 0;}

D

#include<stdio.h>typedef long long LL;LL gcd(LL a, LL b) {    return b ? gcd(b, a % b) : a;}int main(){    LL n, k, res[10];    res[0] = 1;    for(int i = 1; i < 10; ++i) res[i] = res[i - 1] * 10;    while(scanf("%lld %lld", &n, &k) != EOF) {        printf("%lld\n", n * res[k] / gcd(n, res[k]));    }    return 0;}

E

#include <cstdio>int main() {    int n;    while(scanf("%d", &n) != EOF) {        printf("%d\n", n);    }    return 0;}

F

#include<stdio.h>using namespace std;#define LL long longconst int MAXN = 1e6+11;const int inf  = 0x3f3f3f3f;int prm[MAXN+2],sz=0; bool su[MAXN+2];void init(){    su[0]=su[1]=true;    for(int i=2;i<=MAXN;i++){        if(!su[i])  prm[++sz]=i;        for(int j=1;j<=sz;j++){            LL t=1LL*i*prm[j];            if(t>=MAXN) break;            su[t]=true;            if(i%prm[j]==0) break;        }    }}int ans[MAXN];void solve(int m){    if(m==0||m==1) {        puts("HAHA");        return ;    }    int id=0;    for(int i=1;i<=sz&&(LL)prm[i]*prm[i]<=m;i++){        if(m%prm[i]==0) {            ans[id++]=prm[i];            while(m%prm[i]==0)  m/=prm[i];        }    }    if(m>1) ans[id++]=m;    if(id==0) puts("HAHA");    else {        printf("%d\n",id);        for(int i=0;i<id;i++)            printf("%d%s",ans[i],i==id-1?"":" ");        puts("");    }}int main(){    init();    int T;scanf("%d",&T);    while(T--){        int  m;        scanf("%d",&m);        solve(m);    }    return 0;}

or

#include<bits/stdc++.h>#define LL long longusing namespace std;const int MAXN = 1e5;int p[MAXN+2];int id;void getn(int n){    id=0;    for(int i=2;i*i<=n;i++){        if(n%i==0) {           p[id++]=i;           while(n%i==0){            n/=i;           }        }    }    if(n>1) p[id++]=n;}int main(){    int t;cin>>t;    while(t--){        int  m; cin>>m;        getn(m);        if(m==0||m==1||id==0) puts("HAHA");        else {            printf("%d\n",id);            for(int i=0;i<id;i++)                printf("%d%s",p[i],i==id-1?"":" ");            puts("");        }    }    return 0;}

G

#include <stdio.h>const int MAXN = (int)1e6 + 5;int p[MAXN], cnt[MAXN];void init() {    for(int i = 2; i * i < MAXN; ++i) {        if(!p[i]) {            for(int j = i * i; j < MAXN; j += i) {                p[j] = 1;            }        }    }    for(int i = 2; i < MAXN; ++i) {        if(!p[i]) {            for(long long j = i; j < MAXN; j *= i) {                cnt[j] = 1;            }        }    }    for(int i = 1; i < MAXN; ++i) {        cnt[i] += cnt[i - 1];    }}int main(){    init();    int n;    while(scanf("%d", &n) != EOF) {        printf("%d\n", cnt[n]);    }    return 0;}

H

#include <cstdio>struct node{    int hp,sd,sk,tm;    char nature[2];}a,b;int main(){    int t;    scanf("%d",&t);    while (t--){        a.tm = b.tm = 0;        scanf("%d%d%d%s%d%d%d%s",&a.hp,&a.sd,&a.sk,a.nature,&b.hp,&b.sd,&b.sk,b.nature);        if (a.nature[0]!=b.nature[0]){            if (a.nature[0] == 'W'&&b.nature[0] == 'F'){a.sk*=2;b.sk/=2;}            else if (a.nature[0] == 'W'&&b.nature[0] == 'G'){a.sk/=2;b.sk*=2;}            else if (a.nature[0] == 'F'&&b.nature[0] == 'G'){a.sk*=2;b.sk/=2;}            else if (a.nature[0] == 'F'&&b.nature[0] == 'W'){a.sk/=2;b.sk*=2;}            else if (a.nature[0] == 'G'&&b.nature[0] == 'W'){a.sk*=2;b.sk/=2;}            else if (a.nature[0] == 'G'&&b.nature[0] == 'F'){a.sk/=2;b.sk*=2;}        }        a.tm = b.hp/a.sk;if (b.hp%a.sk) a.tm+=1;        b.tm = a.hp/b.sk;if (a.hp%b.sk) b.tm+=1;        if (a.tm == b.tm) if (a.sd > b.sd) a.tm-=1;else b.tm-=1;        if (a.tm<b.tm){            puts("Garry win HAHA! ");        }else puts("No !!!!");    }    return 0;}