2011 Heilongjiang collegiate programming contest训练总结【10/10】

来源:互联网 发布:软件 预研报告 编辑:程序博客网 时间:2024/05/29 17:04

暑假第一场训练赛。


题目:

UESTC 924~933


A.水题,直接模拟即可。


B.水题,直接模拟即可。


C.模拟,按照题意模拟即可,附队友Ac代码:

#include <bits/stdc++.h>#define mme(i,j) memset(i,j,sizeof(i));using namespace std;struct group{    char name[35];    int ac;    int total;    int weight;    int po[22];    int potme[26];    int acnum[26];}gg[205];int pro[25];int protime[25];int n,m;char s[205];void input(){    for(int i=1;i<=n;i++)    {            gg[i].ac=gg[i].total=gg[i].weight=0;            mme(gg[i].po,0);            mme(gg[i].potme,0);            mme(gg[i].acnum,0);            scanf("%s",gg[i].name);            for(int j=1;j<=m;j++){                scanf("%s",s);                int k=0,tme=0;                int num=0;                while(s[k]!='\\' ){                    if(s[k]>='0'&&s[k]<='9')                    {                        num=num*10;                        num=num+s[k]-'0';                    }                    k++;                }                k++;                bool fl=0;                while(s[k]){                    if(s[k]=='-')                    {                        fl=1;                        break;                    }                    tme=tme*10;                    if(s[k]!='-')                        tme=tme+s[k]-'0';                    k++;                }                if(fl==0){                    pro[j]++;                    gg[i].ac++;                    if(protime[j]==-1)                        protime[j]=tme;                    else                        protime[j]=min(protime[j],tme);                    gg[i].po[j]=1;                    gg[i].acnum[j]=num;                    gg[i].potme[j]=tme;                }            }        }        for(int i=1;i<=n;i++){            for(int j=1;j<=m;j++){                if(gg[i].potme[j]==protime[j] )                    gg[i].total+=gg[i].potme[j];                else                {                    if(gg[i].acnum[j]>0)                        gg[i].total+=(gg[i].acnum[j]-1)*20;                    gg[i].total+=gg[i].potme[j];                }            }        }        for(int i=1;i<=m;i++)        {            if(pro[i])                pro[i]=n/pro[i]; // pro is every problem 's weight        }        for(int i=1;i<=n;i++)            for(int j=1;j<=m;j++)                gg[i].weight+=gg[i].po[j]*pro[j];}int cmp(group a1,group a2){    if(a1.ac==a2.ac){        if(a1.total==a2.total){            if(a1.weight == a2.weight)                return strcmp(a1.name,a2.name)<0;            return a1.weight>a2.weight;        }        return a1.total<a2.total;    }    return a1.ac>a2.ac;}int rk[222];int main(){    while(~scanf("%d%d",&n,&m))    {        mme(pro,0);        mme(protime,-1);        input();        sort(gg+1,gg+1+n,cmp);        rk[1]=1;        for(int i=1;i<=n;i++)        {            if(i>1){                if(gg[i].ac==gg[i-1].ac                   &&gg[i].total==gg[i-1].total                   &&gg[i].weight==gg[i-1].weight)                rk[i]=rk[i-1];                else rk[i]=i;            }            printf("%*d %*s %*d %*d %*d\n",3,rk[i],20,gg[i].name,2,gg[i].ac,6,gg[i].total,4,gg[i].weight);        }    }    return 0;}

D.一道很不错的Dp题,我是萌萌哒D题题解


E.可以重复一下第一个字符串,然后去KMP匹配,也可以直接最小表示法搞掉。

我是用最小表示法搞掉的:


#include<stdio.h>#include<string.h>#include<iostream>using namespace std;char a[150000];char bb[150000];int n;int minRepresentation(char b[]){    int l=n;    int i = 0, j = 1, k = 0, t;    while(i < l && j < l && k < l) {        t = b[(i + k) >= l ? i + k - l : i + k] - b[(j + k) >= l ? j + k - l : j + k];        if(!t) k++;        else{            if(t > 0) i = i + k + 1;            else j = j + k + 1;            if(i == j) ++ j;            k = 0;        }    }    return (i < j ? i : j);}int main(){    while(~scanf("%s%s",a,bb))    {        if(strcmp(a,bb)==0)        {            printf("no\n");            continue;        }        if(strlen(a)!=strlen(bb))        {            printf("no\n");            continue;        }        int flag=0;        n=strlen(a);        int posa=minRepresentation(a);        int posb=minRepresentation(bb);        for(int i=0;i<n;i++)        {            if(a[posa]!=bb[posb])flag=1;            posa++;            posb++;            posa%=n;            posb%=n;        }        if(flag==0)        printf("yes\n");        else printf("no\n");    }}

F.一道贪心+前缀和的题,我是萌萌哒F题题解


G.队长做的博弈,窝不会啊.....

#include <bits/stdc++.h>typedef long long int LL;using namespace std;const int N = 10000 +7;map<int,map<int,int> >mmp;int x[N],y[N];int main() {    int n;    while(~scanf("%d",&n)) {        for(int i=1; i<=n; i++)           scanf("%d%d",&x[i],&y[i]);        int flag = 0,xx,yy,t; // equal;        for(int i=1; i<=n; i++) {            mmp.clear();            for(int j=1; j<=n; j++) {                if(i==j) continue;                if(x[i]==x[j]&&y[i]==y[j]) flag=1;                xx=x[i]-x[j];                yy=y[i]-y[j];                if(xx<0) xx*=-1,yy*=-1;                t=__gcd(xx,yy);                xx/=t,yy/=t;                if(mmp[xx][yy]) flag=1;                mmp[xx][yy]=1;            }        }        if(flag ) {            printf("a");        } else {            if(n%(3)==0) printf("b");            else         printf("a");        }        puts(" is the lucky boy.");    }    return 0;}

H.用树状数组Nlogn的去统计一个车前边有多少辆比当前车速度低的个数累加在一起即可。


#include <bits/stdc++.h>typedef long long int LL;using namespace std;const int N = 1000000 +7;struct node{    int x,v;}a[N];bool cmp(node a,node b){    if(a.x==b.x) return a.v<b.v;    return a.x>b.x;}int sum[N];#define lowbit(x) (x&-x)void update(int i,int v){    for(;i<N;i+=lowbit(i)) sum[i]+=v;}int getSum(int i){    int ans = 0; for(;i;i-=lowbit(i)) ans+=sum[i];    return ans;}int main(){    int n;    while(~scanf("%d",&n)){        memset(sum,0,sizeof(sum));        for(int i=1;i<=n;i++)            scanf("%d%d",&a[i].x,&a[i].v);        sort(a+1,a+n+1,cmp);        LL mx = 0;        for(int i=1;i<=n;i++){            mx += getSum(a[i].v-1);            update(a[i].v,1);        }        printf("%lld\n",mx);    }    return 0;}

I.我是萌萌哒I题题解


J.一道数论题,窝不太会,队长做的:

#include <bits/stdc++.h>typedef long long int LL;using namespace std;map<LL,LL >mmp;int main() {    LL n; mmp.clear();    while(~scanf("%lld",&n)) {        if(n%4==3) printf("%lld\n",n*n*2);        else       printf("%d\n",n);    }    return 0;}






阅读全文
0 0
原创粉丝点击