2017年浙江工业大学之江学院程序设计竞赛预赛

来一波水题的题解。(E,G,O没写出来
题目链接 http://115.231.222.240:8081/JudgeOnline/contest.php?cid=1002

A

#include<cstdio>

using namespace std;

int main()
{
    int T,k,n;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&k,&n);
        puts(k%(n+1)?"L":"Z");
    }
    return 0;
}

B

#include<cstdio>
#include<cstring>
using namespace std;
char s[1000+5][20],num[1000+5];
int main()
{
    int n,ansid=0,tal,u=0;char gs[20];
    while(scanf("%d",&n)!=EOF){
        u=ansid=0;
        while(n--){
            scanf("%s",gs);
            tal=0;
            while(tal<u&&strcmp(s[tal],gs)!=0) tal++;
            if(tal<u) num[tal]++;
            if(tal==u){
                strcpy(s[u],gs);
                num[u++]=1;
            }
            if(num[tal]>num[ansid]) ansid=tal;
        }
        puts(s[ansid]);
    }
    return 0;
}

C

#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
    char key[55],str[55];
    while(scanf("%s%s",str,key)!=EOF){
        int len=strlen(key);
        int tal=0;
        for(int i=0;str[i];i++){
            printf("%c",(str[i]-'a'+key[i%len]-'a')%26+'a');
        }
        putchar('\n');
    }
    return 0;
}

D

#include<cstdio>

using namespace std;

double y;
double f(double x){
    return 6*x*x*x+5*x*x+7*x+9.0-y;
}
const double eps=1e-8;
int main()
{

    while(scanf("%lf",&y)!=EOF){
        if(f(0.0)*f(10.0)>0) {puts("No solution!"); continue;}
        double low=0.0,top=10.0;
        while(top-low>eps){
            double mid=(low+top)/2;
            if(f(mid)*f(top)>0) top=mid;
            else low=mid;
        }
        printf("%0.4f\n",top);
    }
    return 0;
}

F

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>

using namespace std;

struct node{int to,cost;};
vector<node> G[220];
int d[220],V,s,e;
typedef pair<int,int> P;

int dijstra(){
    memset(d,0x3f,sizeof(d));
    d[s]=0;
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int dis=p.first,v=p.second;
        if(dis>d[v]) continue;
        for(int i=0;i<G[v].size();i++){
            node &e=G[v][i];
            if(d[e.to]>dis+e.cost){
                d[e.to]=dis+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d[e];
}

int main()
{
    while(scanf("%d%d%d",&V,&s,&e)!=EOF){
        int to,cost;char gs[200*20];
        getchar();
        for(int i=1;i<=V;i++){
            gets(gs);
            for(int j=0;gs[j];j++) if(gs[j]=='('){
                sscanf(gs+j,"(%d %d)",&to,&cost);
                G[i].push_back((node){to,cost});
//              printf("%d %d\n",to,cost);
            }
        }
        int ans=dijstra();
        printf("%d\n",ans);
        for(int i=1;i<=V;i++) G[i].clear();
    }
    return 0;
}

H

#include<cstdio>
#include<algorithm>

using namespace std;

int p[500+5],n,m;

int main()
{
    while(scanf("%d%d",&m,&n)!=EOF&&(n+m)){
        for(int i=0;i<m;i++) scanf("%d",&p[i]);
        sort(p,p+m);
        int ans=0;
        for(int i=0;i<min(n,m);i++) ans+=p[m-i-1];
    //  if(n>m&&p[m-1]>0) ans+=p[m-1]*(n-m);
        printf("%d\n",ans);
    }
    return 0;
}

I,J,K

#pragma GCC optimize ("O2")
#include<cstdio>

using namespace std;

const int MAXN=3e6+1e5;
const int TOP=5e7;
bool p[TOP];int res[MAXN];
void init(){
    for(int i=2;i*i<TOP;i++){
        if(!p[i])
            for(int j=i*i;j<TOP;j+=i) p[j]=true;
    }
    int u=0;
    for(int i=2;i<TOP;i++) if(!p[i]) res[u++]=i;
//  printf("%d\n",u);
}

int main()
{
    init();
    int n,t=0;
    while(scanf("%d",&n)&&n){
        printf("Case %d: %d\n",++t,res[n-1]);
    }
    return 0;
}

加强版
(核心代码当然是抄别人的

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>

using namespace std;

typedef long long LL;

const int MAXN=3e4+2e3;
const int TOP=3e5+8e4;
const int EPS=2e5;
bool p[TOP];int res[MAXN];
bool ints[EPS];

void init(){
    for(int i=2;i*i<TOP;i++) if(!p[i])
        for(int j=i*i;j<TOP;j+=i) p[j]=true;
    int u=0;
    for(int i=2;u<MAXN;i++) if(!p[i]) res[u++]=i;
}

inline LL pn(int n){
    return (LL)floor(n*(log(n*log(n))-1)+n*(log(log(n))-2)/log(n)-6.0*n/1000.0);
}

inline int V2IDX(int v, int N, int Ndr, int nv) {
    return v >= Ndr ? (N/v - 1) : (nv - v);
}

int primesum(LL N) {
    int *S;
    int *V;
    LL r = (LL)sqrt(N);
    LL Ndr = N/r;
    assert(r*r <= N and (r+1)*(r+1) > N);
    LL nv = r + Ndr - 1;
    V = new int[nv];
    S = new int[nv];
    for (int i=0; i<r; i++) {
        V[i] = N/(i+1);
    }
    for (int i=r; i<nv; i++) {
        V[i] = V[i-1] - 1;
    }
    for (int i=0; i<nv; i++) {
        S[i]=V[i] - 1;
    }
    for (int p=2; p<=r; p++) {
        if (S[nv-p] > S[nv-p+1]) {
            int sp = S[nv-p+1];
            int p2 = p*p;
            for (int i=0; i<nv; i++) {
                if (V[i] >= p2) {
                    S[i] -= 1* (S[V2IDX(V[i]/p, N, Ndr, nv)] - sp);
                } else {
                    break;
                }
            }
        }
    }
    return S[0];
}

int main()
{
    init();int ans,t=0,n;
    while(scanf("%d",&n)&&n){
        if(n<MAXN) {printf("Case %d: %d\n",++t,res[n-1]); continue;}
        int a=pn(n);if(a%2&&a>1)a=a-1;
        int b=a+EPS;
        int goal=n-primesum(a);

        int xxx,c;
        memset(ints,0,sizeof(ints));
        for(int i=0;i<MAXN;i++){
            xxx=(int)ceil(1.0*a/res[i]);
            if(xxx==1) xxx++;
            for(int j=xxx;(c=j*res[i])<b;j++) ints[c-a]=1;
        }
        ans=0;
        for(int i=0;i<EPS;i++){
            if(!ints[i]) ans++;
            if(ans==goal){printf("Case %d: %d\n",++t,a+i);break;}
        }
    }
    return 0;
}

L
组合数学题

#include<cstdio>
#include<cstring>

using namespace std;

long long C[40][40];

int init(){
    for(int i=0;i<40;i++) C[i][0]=C[i][i]=1;
    for(int i=2;i<40;i++){
        for(int j=1;j<i;j++){
            C[i][j]=C[i-1][j]+C[i-1][j-1];
//          printf("(%d %d) -> %lld\n",i,j,C[i][j]);
        }
    }
}

int main()
{
//  freopen("out","w",stdout);
    init();
    int a,b,n;
    while(scanf("%d%d%d",&a,&b,&n)!=EOF){
        if(b<a){puts("0"); continue;}
        long long ans=0;
        int k=1;
        int e=0,r=0;
        for(int i=a;i<=b;i++) if(i&1) e++ ; else r++;
        while(k<=e&&n-k>=0){
            ans+=C[e][k]*C[r][n-k];
            k+=2;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

N

#include<cstdio>
#include<cmath>

using namespace std;

double v,a,l,d,t;

int main()
{
    const double PI=acos(-1.0);
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%lf%lf%lf%lf%lf",&v,&a,&l,&d,&t);
        double x=t*v*cos(a/180.0*PI),y=t*v*sin(a/180.0*PI);
//      printf("   %f\n",x);
        double xn=floor(x/d),yn=floor(y/l);
        double xx=x-xn*d,yy=y-yn*l;
        if(xn!=floor(xn/2.0)*2.0) xx=d-xx;
        if(yn!=floor(yn/2.0)*2.0) yy=l-yy;
        printf("(%0.2f,%0.2f)\n",xx,yy);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值