组队赛F 0425总结(未完)

A题: HDU 5090

题意:给N个数,每个数的变化只能加上K的整数倍,问最后能不能形成1...N的排列,第一个是1,第二个是2,...第N个是n;第一反应是贪心,先排序,把小的依次放好,不可以就加K之后再放,依次进行下去,如果1..n都放到了,那就可以,否则不可以。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<cctype>
using namespace std;

#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mem(a, b) memset(a, b, sizeof(a))
#define fir first
#define sec second
#define eps 1e-9
const int maxd=505;
//-----------------------
int a[maxd],cnt[maxd];
int main()
{
    int kase,n,k;
    cin>>kase;
    while(kase--)
    {
        cin>>n>>k;
        mem(cnt,0);
        mem(a,0);
        for(int i=0; i<n; ++i)
            cin>>a[i];

        sort(a,a+n);
        for(int i=0; i<n; ++i)
        {
            int x=a[i];
            while(cnt[x]!=0) x+=k;
            cnt[x]=1;
        }
        bool f=true;
        for(int i=1; i<=n; ++i)
            if(cnt[i]==0)
            {
                f=false;
                break;
            }

        if(!f) cout<<"Tom"<<endl;
        else cout<<"Jerry"<<endl;

    }
    return 0;
}



B题: HDU 5091 线段树扫描


C题: HDU 5092  dp


D题:二分图匹配?


E题   HDU 5094:

  题意:给出迷宫大小和钥匙种类,每两个点之间有不同种类的门必须拿着相应的钥匙才能通过,有墙的不能通过,问从开始到结束的最短路径。

             需要对手中拿到的钥匙进行状态压缩,用三维的数组来记录是否走过的状态,最后一维用来保存已经拿到的钥匙种类,并且还需要注意一个格子里可能有很多钥匙,每两个格子中间可能很多不同种类的门。

          确实没有用过状态压缩,比赛的时候自己想的时候思路是错的,判重的时候处理不了,知道用状压之后很多细节也没处理好,急于交题需要注意的地方也没想到,出的样例也没有测出来错误,导致WA。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<cctype>
using namespace std;

#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mem(a, b) memset(a, b, sizeof(a))
#define fir first
#define sec second
#define eps 1e-9

//------------------------------
const int maxn = 55;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


int g[maxn][maxn][maxn][maxn];
int maze[maxn][maxn];
int vis[maxn][maxn][2030];
int n,m,type;

typedef struct info
{
    int x, y, s ,ss;
};

int change(int x)
{
    int s = 0;
    s = (1 << (x-1));
    return s;
}

void init()
{
    mem(g,-1);
    mem(maze,-1);
    mem(vis,-1);
    int x1,x2,y1,y2,op,w;

    scanf("%d",&op);
    while(op--)
    {
        scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&w);
        if(g[x1][y1][x2][y2]==-1)
        g[x1][y1][x2][y2] = g[x2][y2][x1][y1] = change(w);
        else
        g[x1][y1][x2][y2] +=change(w), g[x2][y2][x1][y1] += change(w);
    }
    scanf("%d",&op);
    while(op--)
    {
        scanf("%d%d%d",&x1,&y1,&w);
        if(maze[x1][y1]==-1)
        maze[x1][y1] = change(w);
        else maze[x1][y1]+=change(w);
    }

}

bool ok(int x,int y)
{
    if(x>0 && y>0 && x<=n && y<=m) return true;
    return false;
}

int bfs(int x,int y)
{
    queue<info> q;

    int ss = 0;
    if(maze[x][y] != -1)
        ss = maze[x][y];

    q.push({x,y,0,ss});
    while(!q.empty())
    {
        info now = q.front();
        q.pop();
 
        if(now.x==n && now.y==m)
            return now.s;

        for(int i=0; i<4; ++i)
        {
            int xx=now.x+dx[i];
            int yy=now.y+dy[i];
            ss=now.ss;
           
            if(ok(xx,yy) && g[now.x][now.y][xx][yy]!=0)
                if(vis[xx][yy][ss]==-1 && (g[now.x][now.y][xx][yy]==-1 || (g[now.x][now.y][xx][yy] & ss)==g[now.x][now.y][xx][yy]))
                {
                    vis[xx][yy][ss]=1;
                    if(maze[xx][yy]!=-1)
                        ss|=maze[xx][yy];
                    
                    q.push({xx,yy,now.s+1,ss});
                    vis[xx][yy][ss]=1;
                }
        }
    }
    return -1;
}


void solve()
{
    int ans = bfs(1,1);
    printf("%d\n",ans);
}

int main()
{
    while(scanf("%d%d%d",&n,&m,&type) != EOF)
    {
        init();
        solve();
    }
    return 0;
}


F题:HDU 5095

    总觉得是大水题没想好就WA了一遍,发现没考虑到系数是1的情况,然后又WA因为最后一个常数是1的时候我的代码没有输出来常数

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<cctype>
using namespace std;

#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mem(a, b) memset(a, b, sizeof(a))
#define fir first
#define sec second
#define eps 1e-9

const int maxd = 10e4;
int a[20];
char x[20]= {'p','q','r','u','v','w','x','y','z'};
int main()
{
    int kase;
    cin>>kase;
    while(kase--)
    {
        for(int i=0; i<10; ++i)
            cin>>a[i];
        bool f=true;
        for(int i=0; i<10; ++i)
            if(a[i])
            {
                if(a[i]>0 && !f) cout<<'+';
                else if(a[i]<0)cout<<'-';

                if(abs(a[i])!=1) cout<<abs(a[i]);

                if(i!=9)
                    cout<<x[i];
                else if(i==9 && abs(a[i])==1)
                    cout<<abs(a[i]);
                f=false;
            }

        if(f) cout<<'0';
        cout<<endl;
    }

    return 0;
}



J题:HDU 5099

    题意理解出现了点问题,着急没读清楚直接就写了好几遍

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<cctype>
using namespace std;

#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mem(a, b) memset(a, b, sizeof(a))
#define fir first
#define sec second
#define eps 1e-9

const int maxd = 10e4;

//------------------------------
string a,b;
void solve()
{
     string c,d;
    for(int i=2; i<=5; ++i)
        c+=a[i],d+=b[i];
    if(c==d)
        cout<<'=';
    else if(c<d)
        cout<<'<';
    else
        cout<<'>';
}

void solve_data()
{
    string c,d;
    for(int i=2; i<5; ++i)
        c+=a[i],d+=b[i];
    if(c==d)
        cout<<'=';
    else if(c<d)
        cout<<'<';
    else
        cout<<'>';
}

int main()
{
    int kase;
    cin>>kase;
    for(int i=1; i<=kase; ++i)
    {
        cin>>a>>b;
        cout<<"Case "<<i<<": ";
        if(a[0]<b[0])
            cout<<"<";
        else if(a[0]==b[0])
            cout<<"=";
        else
            cout<<">";
        cout<<' ';

        if(a[1]==b[1])
            solve();
        else
            solve_data();
        cout<<endl;
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值