GCJ 2015 Round D

9 篇文章 0 订阅


Problem A. Cube IV

#include <iostream>
using namespace std;

int loc[1000001][2];

int main(){
    
    int T,S;
    //scanf("%d",&T);
    
    freopen("/Users/lyd/Downloads/A-large.in", "r", stdin);
    
    scanf("%d",&T);
    
    for (int k=1; k<=T; k++) {
        
        scanf("%d",&S);
        
        for (int i=0; i<S; i++) {
            for (int j=0; j<S; j++) {
                int map;
                scanf("%d",&map);
                loc[map][0]=i;
                loc[map][1]=j;
            }
        }
        
        int res=-1,step=-1;
        int prex=-100,prey=-100;
        int tempres=0;
        //  int MAXS=1<<31;
        
        //  printf("%d",MAXS);
        
        for (int i=S*S; i>=1; i--) {
            int x=loc[i][0];
            int y=loc[i][1];
            
            if (abs(x-prex)+abs(y-prey)==1) {//up,down,left,right
                tempres++;
            }else{
                tempres=1;
            }
            if (tempres>=step) {
                step=tempres;//steps
                res=i;//start point
            }
            
            prex=x;
            prey=y;
        }
        
        printf("Case #%d: %d %d\n",k,res,step);
        
        
    }
    
    return 0;
}


Problem B. GBus count

#include <cstdio>
#include <iostream>
using namespace std;

int main(){
    
    int T,N;
    
    freopen("/Users/lyd/Downloads/B-large.in", "r", stdin);
    
    scanf("%d",&T);
    for (int k=0; k<T ; k++) {

        scanf("%d",&N);
        int **p;
        p=new int *[N];
        
        for (int i=0; i<N; i++) {
            p[i]=new int[2];
        }
        for (int i=0; i<N; i++) {
            scanf("%d %d",&p[i][0],&p[i][1]);
        }
        
        int cN;
        scanf("%d",&cN);
        int *q=new int[cN];
        for (int i=0; i<cN; i++) {
            q[i]=0;
        }
        int ci;
        for (int i=0; i<cN; i++) {
        
            scanf("%d",&ci);
            
            for (int j=0; j<N; j++) {
                if (p[j][0]<=ci&&p[j][1]>=ci) {
                    q[i]++;
                }
            }
        }
        
        printf("Case #%d:",k+1);
        for (int i=0; i<cN; i++) {
            printf(" %d",q[i]);
        }
        printf("\n");
        
    }
    
    return 0;
}

Problem C.  Sort a scrambled itinerary

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int findArr(string str,string s[],int N){
    
    for (int i=0; i<N; i++) {
        if (str==s[i]) {
            return i;
        }
    }
    return -1;
}

int main(){
    
    int T,N;
    
    freopen("/Users/lyd/Downloads/C-large.in", "r", stdin);
    
    scanf("%d",&T);
    for (int k=0; k<T ; k++) {

        scanf("%d",&N);
        
        string *l;
        string *r;
        l=new string [N];
        r=new string [N];
        
        for (int i=0; i<N; i++) {
            cin>>l[i];
            cin>>r[i];
        }
        
        string st;
        string ed;
        
        int si=0;
       // int ei=0;
        //find the start point
        for (int i=0; i<N; i++) {
            //cout<<l[i]<<" "<<r[i]<<endl;
            if (findArr(l[i], r,N)==-1) {
                st=l[i];
                si=i;
            }
        }
        /*
         //find the end point
        for (int i=0; i<N; i++) {
            if (findArr(r[i], l,N)==-1) {
                ed=r[i];
                ei=i;
            }
        }*/
        
        cout<<"Case #"<<k+1<<":";
        
        for (int i=0; i<N; i++) {
            int t=findArr(st, l,N);
            string ed=r[t];
            cout<<" "<<st<<"-"<<ed;
            st=ed;
            si=t;
        }
        
        cout<<endl;
        //cout<<" "<<st<<"-"<<ed<<endl;

        
    }
    
    return 0;
}


Problem D.  Itz Chess



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值