The 2015 China Collegiate Programming Contest(今天睡过头了,干qwq.一点才起来)

A----Secrete Master Plan HDU - 5540(签到)

题意:

给你两张地图,判断能否把一张旋转成另外一张。

思路:

三变量交换法。

AC

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int t,kase=0;scanf("%d", &t);
    while(t--){
        int a,b,c,d,x,y,z,w,tmp;
        cin>>a>>b>>d>>c;
        cin>>x>>y>>w>>z;
        int op=0;
        while(a!=x||b!=y||d!=w||c!=z){
            tmp=a;
            a=b;
            b=c;
            c=d;
            d=tmp;
            op++;
            if(op==4)break;
        }
        if(op<4)printf("Case #%d: POSSIBLE\n",++kase);
        else printf("Case #%d: IMPOSSIBLE\n",++kase);
    }
    return 0;
}

AC(contest时的暴力,还1wa了qwq)

#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
    int t,kase=0;scanf("%d", &t);
    while(t--){
        int a[5],b[5];
        for(int i=1; i<=4; i++)scanf("%d", a+i);
        for(int i=1; i<=2; i++)scanf("%d", b+i);
        scanf("%d",b+4);scanf("%d",b+3);
        printf("Case #%d: ",++kase);
        int j=1;
        vector<int>pos,check;
        check.push_back(a[1]);check.push_back(a[2]);check.push_back(a[4]);check.push_back(a[3]);
        for(j=1; j<=4; j++){
            if(b[j]==a[1])pos.push_back(j);
        }
        int flag=0;
       for(int i=0; i<pos.size(); i++){
        int j=0,k=pos[i];
        for(j=0; j<check.size(); j++){
            if(check[j]!=b[k])break;
            k++;
            if(k>4)k%=4;
        }
        if(j==4)flag=1;
        if(flag)break;
//       int j=0,k=pos[i];
//        for(j=0; j<check.size(); j++){
//            if(check[j]!=b[k])break;
//            k--;
//            if(k==0)k=4;
//        }
//        if(j==4)flag=1;
//        if(flag)break;
       }
        if(flag)printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}

C----The Battle of Chibi HDU - 5542(dp)

题解传送门

G----Ancient Go HDU - 5546(dfs)

题意:

有两人再下棋。问黑子再下一步,是否可以吃白子。

思路:

对于每个 白子的联通块跑dfs,假如白子的联通块附近有,那么就操作一次,假如最后跑完,操作数为1,那么就可以。

AC

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define mp make_pair
#define fi first
#define se second
#define mst(x,a) memset(x,a,sizeof(x))
using namespace std;
typedef pair<int,int>pa;
char s[10][10];
int vis[10][10];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int check(int x,int y){
    queue<pa>q;
    mst(vis,0);
    q.push(mp(x,y));
    vis[x][y]=1;
    int chance=0;
    while(!q.empty()){
        x=q.front().fi;y=q.front().se;
        q.pop();
        vis[x][y]=1;
        //if(x==1||x==9||y==1||y==9)return false;
        for(int i=0; i<4; i++){
            int tx=x+dx[i];
            int ty=y+dy[i];
            if(tx>=1&&tx<=9&&ty>=1&&ty<=9&&!vis[tx][ty]&&s[tx][ty]!='x'){
                if(s[tx][ty]=='.')chance++,vis[tx][ty]=1;
                else q.push(mp(tx,ty));
            }
        }
    }
    return chance;
}
int main()
{
    int t,kase=0;scanf("%d", &t);
    while(t--){
        int flag=0;
        for(int i=1; i<=9; i++)scanf("%s", s[i]+1);
        for(int i=1; i<=9; i++){
            for(int j=1; j<=9; j++){
                if(s[i][j]=='o'){
                    if(check(i,j)==1){
                        flag=1;
                        break;
                    }
                }
            }
            if(flag)break;
        }
        printf("Case #%d: ",++kase);
        if(flag)printf("Can kill in one move!!!\n");
        else printf("Can not kill in one move!!!\n");
    }
    return 0;
}

L----Sudoku HDU - 5547 (dfs&&暴力)

题意:

4 x 4 的数独游戏,要求模拟

思路:

  1. 保证行列可以填数,且2 x 2 可以填时,还剩一个就填数。
  2. 通过行列,计算冲突,再把2 x 2 里没填的数(假如冲突就不填,有一个就填)。

AC

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define mst(x,a) memset(x,a,sizeof(x))
using namespace std;
char s[10][10];
int ma[10][10];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int flag=0;
int row[5][5],col[5][5],vis[10][10],matx[5][5];
void put(int x, int y){
    if(ma[x][y])return;
    int num=0;
    if(x>=1&&x<=2&&y>=1&&y<=2)num=1;//matx[1][ma[x][y]]=1;
    else if(x>=1&&x<=2&&y>=3&&y<=4)num=2;//matx[2][ma[x][y]]=1;
    else if(x>=3&&x<=4&&y>=1&&y<=2)num=3;//matx[3][ma[x][y]]=1;
    else if(x>=3&&x<=4&&y>=3&&y<=4)num=4;//matx[4][ma[x][y]]=1;
    //cout<<x<<' '<<y<<' '<<num<<endl;
    vector<int>rowt,colt,matxt;
    for(int i=1; i<=4; i++)if(!row[x][i])rowt.push_back(i);
    for(int i=1; i<=4; i++)if(!col[y][i])colt.push_back(i);
    for(int i=1; i<=4; i++)if(!matx[num][i])matxt.push_back(i);
   //caculate the conflict
    vector<int>ans;
    for(int i=0; i<matxt.size(); i++){
        if(row[x][matxt[i]]);
        else if(col[y][matxt[i]]);
        else ans.push_back(matxt[i]);
    }
    if(ans.size()==1){
        col[y][ans[0]]=1,row[x][ans[0]]=1,ma[x][y]=ans[0];
        matx[num][ma[x][y]]=1;
        return ;
    }
}
void dfs(int x, int y){
    vis[x][y]=1;
    put(x,y);
    for(int i=0; i<4; i++){
        int tx=x+dx[i];
        int ty=y+dy[i];
        if(tx>=1&&tx<=4&&ty>=1&&ty<=4&&!vis[tx][ty])dfs(tx,ty);
    }
    put(x,y);
}
bool check(){
    for(int i=1; i<=4; i++){
        for(int j=1; j<=4; j++)if(!ma[i][j])return false;
    }
    return true;
}
int main()
{
    int t,kase=0;scanf("%d", &t);
    while(t--){
        mst(matx,0);mst(row,0);mst(col,0);mst(vis,0);
        for(int i=1; i<=4; i++)scanf("%s", s[i]+1);
        for(int i=1; i<=4; i++){
            for(int j=1; j<=4; j++){
                if(s[i][j]=='*')ma[i][j]=0;
                else ma[i][j]=s[i][j]-'0',row[i][ma[i][j]]=1,col[j][ma[i][j]]=1;
            }
        }
        for(int i=1; i<=4; i++){
            for(int j=1; j<=4; j++){
                if(i>=1&&i<=2&&j>=1&&j<=2&&ma[i][j])matx[1][ma[i][j]]=1;
                else if(i>=1&&i<=2&&j>=3&&j<=4&&ma[i][j])matx[2][ma[i][j]]=1;
                else if(i>=3&&i<=4&&j>=1&&j<=2&&ma[i][j])matx[3][ma[i][j]]=1;
                else if(i>=3&&i<=4&&j>=3&&j<=4&&ma[i][j])matx[4][ma[i][j]]=1;
            }
        }
        printf("Case #%d:\n", ++kase);
        while(!check()){
        mst(vis,0);
        dfs(1,1);
       }
        for(int i=1; i<=4; i++){
            for(int j=1;j<=4; j++)printf("%d",ma[i][j]);
            puts("");
        }
    }
    return 0;
}

L----Huatuo’s Medicine-HDU - 5551(水题)

题意:

华佗有n终瓶子,问最后至少带几个瓶子。

思路:

两边夹住就行了。
a n s = n ∗ 2 − 1 ans=n*2-1 ans=n21

AC

#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,kase=0;cin>>t;
    while(t--){
        int n;cin>>n;
        cout<<"Case #"<<++kase<<": ";
        cout<<2*n-1<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值