2015 Multi-University Training Contest 4(hdu 5327 - hdu 5338)

1.Olympiad

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5327

解题思路:http://blog.csdn.net/piaocoder/article/details/47192393

#include <iostream>  
#include <cstdio>  
#include <cstring>  
using namespace std;  
  
int vis[10];  
int f[100005];  
  
int main(){  
    for(int i = 1; i <= 100000; i++){  
        memset(vis,0,sizeof(vis));  
        int tmp = i;  
        while(tmp){  
            if(vis[tmp%10]){  
                f[i] = f[i-1];  
                break;  
            }  
            vis[tmp%10] = 1;  
            tmp /= 10;  
        }  
        if(tmp == 0)  
            f[i] = f[i-1] + 1;  
    }  
    int T;  
    scanf("%d",&T);  
    while(T--){  
        int a,b;  
        scanf("%d%d",&a,&b);  
        printf("%d\n",f[b]-f[a-1]);  
    }  
    return 0;  
}  


2.Problem Killer

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328

解题思路:http://blog.csdn.net/piaocoder/article/details/47192429

#include <iostream>  
#include <cstdio>  
#include <algorithm>  
using namespace std;  
  
int main(){  
    int T;  
    scanf("%d",&T);  
    while(T--){  
        double ap;  
        double gp;  
        int n;  
        scanf("%d",&n);  
        double a,b;  
        int sumap = 2,sumgp = 2,ans = 2;  
        scanf("%lf",&a);  
        if(n == 1){  
            printf("1\n");  
            continue;  
        }  
        scanf("%lf",&b);  
        ap = b - a;  
        gp = b / a;  
        a = b;  
        double tmap,tmgp;  
        for(int i = 2; i < n; i++){  
            scanf("%lf",&b);  
            tmap = b - a;  
            tmgp = b / a;  
            if(ap == tmap)  
                sumap++;  
            else{  
                ans = max(ans,sumap);  
                sumap = 2;  
                ap = tmap;  
            }  
            if(gp == tmgp)  
                sumgp++;  
            else{  
                ans = max(ans,sumgp);  
                sumgp = 2;  
                gp = tmgp;  
            }  
            a = b;  
        }  
        ans = max(ans,sumap);  
        ans = max(ans,sumgp);  
        printf("%d\n",ans);  
    }  
    return 0;  
}  


3.Question for the Leader


4.Route Statistics


5.Simple Problem


6.Test for Rikka


7.Undirected Graph


8.Virtual Participation


9.Walk Out

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5335

解题思路:http://blog.csdn.net/piaocoder/article/details/47192695

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1010;
struct node
{
    int x, y;
};
char a[maxn][maxn];
bool vis[maxn][maxn];
int dir[4][2] = {1,0, 0,1, -1,0, 0,-1};
int x, y, n, m;
bool check (int x, int y)
{
    if (x<0 || y<0 || x>=n || y>=m)
        return false;
    return true;
}
void bfs ()
{
    node p, q;
    p.x = x, p.y = y;
    queue <node> Q;
    Q.push (p);
    while (!Q.empty())
    {
        p = Q.front();
        Q.pop();
        for (int i=0; i<4; i++)
        {
            q.x = p.x + dir[i][0];
            q.y = p.y + dir[i][1];
            if (check(q.x, q.y) && !vis[q.x][q.y])
            {
                vis[q.x][q.y] = true;
                if (a[q.x][q.y] == '0')
                    Q.push (q);
                if (x + y < q.x + q.y)
                    x = q.x, y = q.y;
            }
        }
    }
}
int main ()
{
    int t;
    scanf ("%d", &t);
    while (t --)
    {
        memset (vis, false, sizeof(vis));
        vis[0][0] = true;
        scanf ("%d %d", &n, &m);
        for (int i=0; i<n; i++)
            scanf ("%s", a[i]);
        x = y = 0;
        if (a[x][y] == '0')
            bfs ();
        if (a[x][y] == '0')
            putchar('0');
        else
        {
            bool nowflag = false;
            putchar ('1');
            for (int i=x+y; i<n+m-2; i++)
            {
                bool flag = false;
                for (x=0; x<=i; x++)
                {
                    y = i - x;
                    if (!check(x, y) || !vis[x][y])
                        continue;
                    if (nowflag && a[x][y]=='1')
                        continue;
                    for (int j=0; j<2; j++)
                    {
                        int xx = x + dir[j][0];
                        int yy = y + dir[j][1];
                        if (!check(xx,yy))
                            continue;
                        vis[xx][yy] = true;
                        if (a[xx][yy] == '0')
                            flag = true;
                     }
                }
                nowflag = flag;
                putchar (flag?'0':'1');
            }
        }
        puts("");
    }
    return 0;
}


10.XYZ and Drops

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336

解题思路:http://blog.csdn.net/piaocoder/article/details/47192767

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

const int maxn=110;
struct node
{
    int x,y,val,t;
}no[maxn];
struct water
{
    int x,y,t,id,dir;
    water(){}
    water(int _x,int _y,int _t,int _id,int _dir):x(_x),y(_y),t(_t),id(_id),dir(_dir){}
    bool operator < (const water &a) const
    {
        return t > a.t;
    }
};

int r,c,n,T;
int vis[maxn][maxn];

void solve(int x,int y,priority_queue<water> &q,int t)
{
    int tmp = x;
    vis[x][y] = -1;
    while(tmp>0 && vis[tmp][y]==-1)
        tmp--;
    q.push(water(tmp,y,t+x-tmp,tmp==0?-1:vis[tmp][y],1));
    tmp = x;
    while(tmp<=r && vis[tmp][y]==-1)
        tmp++;
    q.push(water(tmp,y,t+tmp-x,tmp>r?-1:vis[tmp][y],2));
    tmp = y;
    while(tmp>0 && vis[x][tmp]==-1)
        tmp--;
    q.push(water(x,tmp,t+y-tmp,tmp==0?-1:vis[x][tmp],3));
    tmp = y;
    while(tmp<=c && vis[x][tmp]==-1)
        tmp++;
    q.push(water(x,tmp,t+tmp-y,tmp>c?-1:vis[x][tmp],4));
}
void bfs(int x,int y)
{
    priority_queue<water> q;
    solve(x,y,q,0);

    while(!q.empty())
    {
        water u = q.top();
        q.pop();
        if(u.id == -1)
            continue;
        if(u.t > T)
            continue;
        if(no[u.id].val <= 4 && vis[u.x][u.y] != -1)
        {
            no[u.id].t = u.t;
            no[u.id].val++;
            if(no[u.id].val>4)
                solve(no[u.id].x,no[u.id].y,q,u.t);
        }
        else if(no[u.id].val>4 && no[u.id].t<u.t)
        {
            int x = u.x,y = u.y;
            int tmp,t = u.t;
            if(u.dir == 1)
            {
                tmp = x;
                while(tmp>0 && vis[tmp][y]==-1)
                    tmp--;
                if(tmp > 0)
                    q.push(water(tmp,y,t+x-tmp,vis[tmp][y],1));
            }
            else if(u.dir == 2)
            {
                tmp = x;
                while(tmp<=r && vis[tmp][y]==-1)tmp++;
                if(tmp <= r)
                    q.push(water(tmp,y,t+tmp-x,vis[tmp][y],2));
            }
            else if(u.dir == 3)
            {
                tmp = y;
                while(tmp>0 && vis[x][tmp]==-1)
                    tmp--;
                if(tmp > 0)
                    q.push(water(x,tmp,t+y-tmp,vis[x][tmp],3));
            }
            else
            {
                tmp = y;
                while(tmp<=c && vis[x][tmp]==-1)
                    tmp++;
                if(tmp <= c)
                    q.push(water(x,tmp,t+tmp-y,vis[x][tmp],4));
            }
        }
    }
}

int main()
{
    while(scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF)
    {
        memset(vis,-1,sizeof(vis));
        for(int i = 1;i <= n; i++)
        {
            scanf("%d%d%d",&no[i].x,&no[i].y,&no[i].val);
            vis[no[i].x][no[i].y] = i;
        }
        int x,y;
        scanf("%d%d",&x,&y);
        bfs(x,y);
        for(int i = 1; i <= n; i++)
        {
            if(no[i].val > 4)
                printf("0 %d\n",no[i].t);
            else
                printf("1 %d\n",no[i].val);
        }
    }
    return 0;
}


11.Yet Another XYZ Problem


12.ZZX and Permutations

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值