第六届河南省程序设计大赛

来源:互联网 发布:林书豪上赛季数据 编辑:程序博客网 时间:2024/04/20 09:42

nyoj709 : 异 形 卵
题意: 略。
思路:找热量最大的,有多个找位置小的。

AC代码:

#include <cstdio>#include <cstring>const int maxn=1010;int sum[maxn];int main(){ //   freopen("1.txt","r",stdin);    int t;    int l,n;    scanf("%d",&t);    while(t--){        memset(sum,0,sizeof(sum));        scanf("%d%d",&l,&n);        int x;        for(int i=1; i<=n; i++){            scanf("%d",&x);            sum[i]=sum[i-1]+x;        }        int f=0,k=0;        int s=0;        for(int i=n; i>=l; i--){            if(sum[i]-sum[i-l]>=s){                s=sum[i]-sum[i-l];                f=1; k=i-l+1;            }        }        if(f) printf("%d\n",k);        else printf("0\n");    }    return 0;}

nyoj710:外星人的供给站
题意:略。
思路:贪心。poj有一题和这题一样。

AC代码:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;struct ac{    double l,r;}p[105];bool cmp(ac a,ac b){    return a.l<b.l;}int main(){    int T;    int n;    double r;    scanf("%d",&T);    while(T--){        double x,y;        scanf("%d%lf",&n,&r);        for(int i=1; i<=n; i++){            scanf("%lf%lf",&x,&y);            p[i].l=x-sqrt(r*r-y*y);            p[i].r=x+sqrt(r*r-y*y);        }        sort(p+1,p+n+1,cmp);        int ans=1;        double k=p[1].r;        for(int i=2; i<=n; i++){            if(p[i].r<k) k=p[i].r;            else if(p[i].l>k){                ans++;                k=p[i].r;            }        }        printf("%d\n",ans);    }    return 0;}

nyoj711: 最舒适的路线
题意:略。
思路: 图论题。
先判断能不能从s到t,若不能直接输出结果。
若能,每次枚举边。判断s和t有没有联通。求出比值最小的。

AC代码:

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define INF 0x3f3f3f3fusing namespace std;struct ac{    int x,y;    int d;}p[5550];int f[5550];int cnt;int n,m;int s,t;void init(){    for(int i=1; i<=5550; i++) f[i]=i;    cnt=0;}int gcd(int x,int y){    if(y==0) return x;    else return gcd(y,x%y);}bool cmp(ac a,ac b){    return a.d<b.d;}int Find(int x){    int r=x;    while(r!=f[r]){        r=f[r];    }    int j=x;    while(f[j]!=r){        int i=f[j];        f[j]=r;        j=i;    }    return r;}void solve(){    int st,ed;    double ans=1000000000.0;    for(int i=1; i<=m; i++){        init();        for(int j=i; j<=m; j++){            int fx=Find(p[j].x);            int fy=Find(p[j].y);            if(fx!=fy){                cnt++;                f[fx]=fy;            }            if(Find(s)==Find(t)){                double xx=(double)(p[j].d*1.0);                double yy=(double)(p[i].d*1.0);                double xy=xx/yy;                if(xy<ans){                    ans=xy;                    st=p[j].d; ed=p[i].d;                }                break;            }        }    }  //  printf("st=%d ed=%d\n",st,ed);    if(st%ed==0){        printf("%d\n",st/ed);    }    else {        int k=gcd(st,ed);        printf("%d/%d\n",st/k,ed/k);    }}int main(){    int tt;    scanf("%d",&tt);    for(int i=1; i<=tt; i++){        init();        scanf("%d%d",&n,&m);        for(int i=1; i<=m; i++){            scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].d);            if(Find(p[i].x)!=Find(p[i].y)){                f[p[i].x]=f[p[i].y];            }        }        scanf("%d%d",&s,&t);        if(Find(s)!=Find(t)){            printf("IMPOSSIBLE\n"); continue;        }        sort(p+1,p+m+1,cmp);        solve();    }    return 0;}

nyoj712:探 寻 宝 藏
题意:略。
思路:双线程dp。和传纸条一样。
AC代码:

#include <cstdio>#include <cstring>const int maxn=55;int dp[maxn*2][maxn][maxn];int a[maxn][maxn];int Max(int a,int b,int c,int d){    if(a<b) a=b;    if(a<c) a=c;    if(a<d) a=d;    return a;}int main(){    int t;    int m,n;    scanf("%d",&t);    while(t--){        scanf("%d%d",&m,&n);        for(int i=1; i<=m; i++){            for(int j=1; j<=n;j++){                scanf("%d",&a[i][j]);            }        }        memset(dp,0,sizeof(dp));        for(int i=3; i<=m+n; i++){            for(int x1=1; x1<=m; x1++){                for(int x2=1; x2<=m; x2++){                    if(i-x1>n || i-x1<1) continue;                    if(i-x2>n || i-x2<1) continue;                    if(x1==x2) continue;                    dp[i][x1][x2]=Max(dp[i-1][x1][x2],dp[i-1][x1-1][x2],dp[i-1][x1][x2-1],dp[i-1][x1-1][x2-1]);                    dp[i][x1][x2]+=(a[x1][i-x1]+a[x2][i-x2]);                }            }        }        printf("%d\n",dp[m+n-1][m-1][m]+a[m][n]+a[1][1]);    }    return 0;}
0 0
原创粉丝点击