现在的位置: 首页 > 综合 > 正文

hdu 4119 && hdu 4082 && hdu 4054

2014年02月25日 ⁄ 综合 ⁄ 共 3447字 ⁄ 字号 评论关闭

下午重新写了去年区域赛的三道模拟题

hdu 4119

#include<cstdio>
#include<cstring>
#include<math.h>
#include<set>
#include<algorithm>
#define N 60
#define P 1000000007
using namespace std;
typedef unsigned long long ull;
char map[N][N],cha[4][N][N],str[4000],ans[4000];
int cnt,n,m,flag;
set<ull>s;
int main(){
    int t,T,i,j,k,p,q;
    char word[30];
    ull tmp;
    int len;
    scanf("%d",&T);
    for(t=1;t<=T;t++){
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            scanf("%s",&map[i][1]);
        for(i=1;i<=n;i++)
            scanf("%s",&cha[0][i][1]);
        for(k=1;k<=3;k++){
            for(i=1;i<=n;i++)
                for(j=1;j<=n;j++)
                    cha[k][j][n+1-i]=cha[k-1][i][j];
        }
        scanf("%d",&m);
        s.clear();
        for(i=1;i<=m;i++){
            scanf("%s",&word);
            len=strlen(word);
            tmp=0;
            for(j=0;j<len;j++)
                tmp=tmp*P+word[j];
            s.insert(tmp);
        }
        flag=0;
        for(k=0;k<4;k++){
            int be=0,first=1,cnt=0;
            for(i=0;i<4;i++){
                for(p=1;p<=n;p++)
                    for(q=1;q<=n;q++)
                        if(cha[(i+k)%4][p][q]!='.'){
                            if(map[p][q]!='.'){
                                str[cnt++]=map[p][q];
                                be=0;
                                first=0;
                            }
                            else{
                                if(!first && !be){
                                    str[cnt++]=' ';
                                    be=1;
                                }
                            }
                        }
            }
            if(str[cnt-1]==' ')
                str[--cnt]='\0';
            else
                str[cnt]='\0';
            tmp=0;
            bool ok=1;
            for(i=0;i<cnt;i++){
                if(str[i]==' '){
                    if(s.find(tmp)==s.end()){
                        ok=0;
                        break;
                    }
                    tmp=0;
                }
                else
                    tmp=tmp*P+str[i];
            }
            if(s.find(tmp)==s.end())
                ok=0;
            if(ok){
                if(!flag){
                    flag=1;
                    strcpy(ans,str);
                }
                else if(strcmp(ans,str)>0)
                    strcpy(ans,str);
            }
        }
        if(flag)
            printf("Case #%d: %s\n",t,ans);
        else
            printf("Case #%d: FAIL TO DECRYPT\n",t);
    }
}

hdu 4082

#include<cstdio>
#include<cstring>
#include<math.h>
#include<set>
#include<algorithm>
using namespace std;
struct Point{
    int x,y;
}p[20];
struct Triangle{
    int a,b,c;
}tri[10010];
bool vis[300][300];
int ok(int i,int j,int k){
    int x1=p[i].x-p[j].x;
    int x2=p[j].x-p[k].x;
    int y1=p[i].y-p[j].y;
    int y2=p[j].y-p[k].y;
    if(x1*y2==x2*y1)return 0;
    return 1;
}
int similar(int i,int j){
    if(tri[i].a*tri[j].b==tri[i].b*tri[j].a && tri[i].a*tri[j].c==tri[i].c*tri[j].a)return 1;
    return 0;
}
int main(){
    int n,nn,i,j,k,x,y,cnt;
    while(scanf("%d",&n)){
        if(n==0)break;
        memset(vis,0,sizeof(vis));
        nn=0;
        for(i=1;i<=n;i++){
            scanf("%d %d",&x,&y);
            if(vis[x+110][y+110])continue;
            vis[x+110][y+110]=1;
            p[nn].x=x,p[nn].y=y,nn++;
        }
        cnt=0;
        for(i=0;i<nn;i++)
            for(j=i+1;j<nn;j++)
                for(k=j+1;k<nn;k++){
                    if(ok(i,j,k)){
                        tri[cnt].a=(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);
                        tri[cnt].b=(p[i].x-p[k].x)*(p[i].x-p[k].x)+(p[i].y-p[k].y)*(p[i].y-p[k].y);
                        tri[cnt].c=(p[k].x-p[j].x)*(p[k].x-p[j].x)+(p[k].y-p[j].y)*(p[k].y-p[j].y);
                        if(tri[cnt].a>tri[cnt].c)swap(tri[cnt].a,tri[cnt].c);
                        if(tri[cnt].b>tri[cnt].c)swap(tri[cnt].b,tri[cnt].c);
                        if(tri[cnt].a>tri[cnt].b)swap(tri[cnt].a,tri[cnt].b);
                        cnt++;
                    }
                }
        if(cnt==0){
            printf("0\n");
            continue;
        }
        int ans=0;
        for(i=0;i<cnt;i++){
            int now=0;
            for(j=i+1;j<cnt;j++){
                if(similar(i,j))
                    now++;
            }
            if(now>ans)
                ans=now;
        }
        printf("%d\n",ans+1);
    }
}

hdu 4054

#include<cstdio>
#include<cstring>
#include<math.h>
#include<set>
#include<algorithm>
#define P 1000000007
using namespace std;
typedef unsigned long long ull;
char s[5010];
int main(){
    int l,len,xun;
    int i,j;
    while(gets(s)!=0){
        len=strlen(s);
        l=0;
        xun=len/16;
        int flag=(len%16!=0);
        for(i=0;i<xun;i++){
            printf("%04x:",i*16);
            for(j=16*i;j<16*i+16;j+=2)
                printf(" %x%x",s[j],s[j+1]);
            printf(" ");
            for(j=16*i;j<16*i+16;j++)
                if(s[j]>='a' && s[j]<='z')
                    printf("%c",s[j]+('A'-'a'));
                else if(s[j]>='A' && s[j]<='Z')
                    printf("%c",s[j]+('a'-'A'));
                else
                    printf("%c",s[j]);
            printf("\n");
        }
        if(flag){
            printf("%04x:",xun*16);
            for(j=0;j<len%16;j++){
                if(j%2==0)
                    printf(" %x",s[j+xun*16]);
                else
                    printf("%x",s[j+xun*16]);
            }
            for(;j<16;j++){
                if(j%2==0)
                    printf("   ");
                else
                    printf("  ");
            }
            printf(" ");
            for(j=0;j<len%16;j++)
                if(s[j+xun*16]>='a' && s[j+xun*16]<='z')
                    printf("%c",s[j+xun*16]+('A'-'a'));
                else if(s[j+xun*16]>='A' && s[j+xun*16]<='Z')
                    printf("%c",s[j+xun*16]+('a'-'A'));
                else
                    printf("%c",s[j+xun*16]);
            printf("\n");
        }
    }
}

抱歉!评论已关闭.