2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 - A C F H

A: Banana

time limit

200ms

memory limit

131072KB

Bananas are the favoured food of monkeys.

In the forest, there is a Banana Company that provides bananas from different places.

The company has two lists.

The first list records the types of bananas preferred by different monkeys, and thesecond one records the types of bananas from different places.

Now, the supplier wants to know, whether a monkey can accept at least one type ofbananas from a place.

Remenber that, there could be more than one types of bananas from a place, and therealso could be more than one types of bananas of a monkey's preference.

Input Format

The first line contains an integer T , indicating that there are T test cases.
For each test case, the first line contains two integers
N and M, representing the

length of the first and the second lists respectively.
In the each line of following
N lines, two positive integers i, j indicate that the i-th

monkey favours the j-th type of banana.
In the each line of following
M lines, two positive integers j, k indicate that the j-th

type of banana could be find in the k-th place.All integers of the input are less than 50.

Output Format

page1image13536

For each test case, output all the pairs x, y that the x-the monkey can accept at leastone type of bananas from the y-th place.

These pairs should be outputted as ascending order. That is say that a pair of x, ywhich owns a smaller x should be output first.

If two pairs own the same x, output the one who has a smaller y first.And there should be an empty line after each test case. 


题意:

已知每个猴子对应香蕉种类,每个香蕉种类对应供应商。

求猴子对应的供应商。

#include <vector>
#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;
#define LL long long
const int inf = 0x3f3f3f3f;
const int maxn =55;
int mp[maxn][maxn];
int hou[maxn][maxn];
int h[maxn],ban[maxn];
void init()
{
    memset(mp,0,sizeof mp);
    memset(hou,0,sizeof hou);
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        init();
        int n,m;
        scanf("%d %d",&n,&m);
        for(int i=1;i<=n;i++) scanf("%d %d",&h[i],&ban[i]);
        for(int i=1;i<=m;i++)
        {
            int a,b;scanf("%d %d",&a,&b);//香蕉 店
            mp[a][b]=1;
        }
        for(int i=1;i<=n;i++)
        {
            int ho=h[i];
            int b=ban[i];
            for(int j=1;j<=50;j++)
            {
                if(mp[b][j])
                {
                    hou[ho][j]=1;
                }
            }
        }
        for(int i=1;i<=50;i++)
        {
            for(int j=1;j<=50;j++)
            {
                if(hou[i][j]==1)
                {
                    printf("%d %d\n",i,j);
                }
            }
        }
        printf("\n");
    }
    return 0;
}



C: Coconut

time limit

200ms

memory limit

131072KB
Coconut is Captain Gangplank's favourite fruit. That is why he needs to drink coconut

juice from b coconuts each day.

On his next trip, he would pass through N citis.

His trip would begin in the 1-st city and end in the N-th city.

The journey from the i-th city to the (i + 1)-th city costs Di days.

Initially, there is no coconut on his ship. Fortunately, he could get supply of Ci coconutsfrom the i-th city.

Could you tell him, whether he could drink coconut juice every day during the trip no not?

page4image12192

Input Format

The first line contains an integer T , indicating that there are T test cases.
For each test case the first line contains two integers
N and b as described above.The second line contains N integers C1 , C2 , ⋯ , CN .
The third line contains
N − 1 integers D1 , D2 , ⋯ , DN −1 .
All integers in the input are less than
1000.

Output Format

For each case, output Yes if Captain Gangplank could drink coconut juice every day,and otherwise output No. 


题意:

从1按顺序走到n,给你每条路用的时间,和每天要喝的数量,每座城市有的饮料数。

判断中途会不会喝光,喝光no。


#include <vector>
#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;
#define LL long long
const int inf = 0x3f3f3f3f;
const int maxn =1100;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,b;
        scanf("%d %d",&n,&b);
        int c[maxn];
        int d[maxn];
        for(int i=1;i<=n;i++) scanf("%d",&c[i]);
        for(int i=1;i<n;i++) scanf("%d",&d[i]);
        int now=c[1];
        int flag=1;
        for(int i=1;i<n;i++)
        {
            if(now<d[i]*b)
            {
                flag=0;
                break;
            }
            else
                now=now-d[i]*b+c[i+1];
        }
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

F: Islands

time limit

1000ms

memory limit

131072KBpage8image9400

On the mysterious continent of Tamriel, there is a great empire founded by human.

To develope the trade, the East Empire Company is set up to transport goods fromplace to place.

Recently, the company wants to start their business in Solstheim, which is consists of Nislands.

Luckily, there are already M sea routes.
All routes are one-way, and the
i-th route can transport person and goods from island ui

to vi.
Now, the company nominates you a particular job to plan some new routes to make

sure that person and goods can be transported between any two islands.

Furthermore, because the neighboring regions are under attack by an increasingnumber of dragons, limited resources can be used to set up new routes.

So you should plan to build new routes as few as possible.

Input Format

The first line contains an integer T , indicating that there are T test cases.For each test case, the first line includes two integers N (N ≤ 10000) and

M (M ≤ 100000), as described above.
After that there are
M lines. Each line contains two integers ui and vi.

Output Format

For each test case output one integer, represent the least number of routes required tonew. 


题意:

给你n个点和m条边,求出在添加几条边变成强连通。

point:

tarjan算法。


#include <vector>
#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <stack>
#include <string.h>
using namespace std;
#define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = 10000 + 10;
const int maxm = 100000 + 10;
vector<int> G[maxn];
int T;
int n,m;
int cor[maxn],numcor,low[maxn],dfn[maxn],tm;
int inq[maxn];
stack<int> q;
void init()
{
    for(int i=0;i<=n;i++) G[i].clear();
    numcor=0;
    memset(cor,0,sizeof cor);
    memset(low,0,sizeof low);
    memset(dfn,0,sizeof dfn);
    memset(inq,0,sizeof inq);
    tm=0;
    while(!q.empty()) q.pop();
}
void tanjar(int u)
{
    dfn[u]=low[u]=++tm;
    q.push(u);
    inq[u]=1;
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if(dfn[v]==0)
        {
            tanjar(v);
            if(low[u]>low[v])
            {
                low[u]=low[v];
            }
        }
        else if(inq[v]==1&&low[u]>dfn[v])
        {
            low[u]=dfn[v];
        }
    }
    if(dfn[u]==low[u])
    {
        numcor++;
        int v;
        do
        {
            v=q.top();
            cor[v]=numcor;
            inq[v]=0;
            q.pop();
        }
        while(v!=u);
        
    }
}
int main()
{
    scanf("%d",&T);
    while(T--)//特判
    {
        scanf("%d %d",&n,&m);
        init();
        int uu[maxm],vv[maxm];
        for(int i=1;i<=m;i++)
        {
            int u,v;scanf("%d %d",&u,&v);
            G[u].push_back(v);
            uu[i]=u;
            vv[i]=v;
        }
        for(int i=1;i<=n;i++)
        {
            if(dfn[i]==0)
            {
                tanjar(i);
            }
        }
        int ru[maxn],chu[maxn];
        memset(ru,0,sizeof ru);
        memset(chu,0,sizeof chu);
        for(int i=1;i<=m;i++)
        {
            if(cor[vv[i]]==cor[uu[i]]) continue;
            ru[cor[vv[i]]]++;
            chu[cor[uu[i]]]++;
        }
        int ru0=0,chu0=0;
        int k=0;
        for(int i=1;i<=numcor;i++)
        {
            if(ru[i]==0&&chu[i]==0)
            {
               k++;
            }
            if(ru[i]==0) ru0++;
            if(chu[i]==0) chu0++;
        }
        if(k==1&&numcor==1) printf("0\n");
        else
        {
            printf("%d\n",max(ru0,chu0));
        }
    }
    
    return 0;
}


H: Skiing

time limit

1000ms

memory limit

131072KB

page11image9944

In this winter holiday, Bob has a plan for skiing at the mountain resort.

This ski resort has M different ski paths and N different flags situated at those turningpoints.

The i-th path from the Si-th flag to the Ti-th flag has length Li.
Each path must follow the principal of reduction of heights and the start point must be

higher than the end point strictly.

An available ski trail would start from a flag, passing through several flags along thepaths, and end at another flag.

Now, you should help Bob find the longest available ski trail in the ski resort.

Input Format

The first line contains an integer T , indicating that there are T cases.
In each test case, the first line contains two integers
N and M where 0 < N ≤ 10000

and 0 < M ≤ 100000 as described above.
Each of the following
M lines contains three integers Si, Ti, and Li (0 < Li < 1000)

describing a path in the ski resort.

Output Format

For each test case, ouput one integer representing the length of the longest ski trail. 



题意:

n个点,m条边,求出能走的最长路。


point:

记忆化搜索。队友的代码。


#include <vector>
#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;
#define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = 10000 + 10;
int n,m,t,vis[maxn];
struct node
{
    int next,dist;
    node(int a,int b){next = a,dist = b;}
};
vector<node>e[maxn];
int dfs(int x)
{
    if(vis[x]) return vis[x];
    for(int i=0;i<e[x].size();i++)
    {
        int nx = e[x][i].next,dis = e[x][i].dist;
        vis[x] = max(vis[x],dfs(nx)+dis);
    }
    return vis[x];
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int ans = 0;
        memset(vis,0,sizeof vis);
        scanf("%d%d",&n,&m);
        for(int i=0;i<=n;i++) e[i].clear();
        for(int i=0;i<m;i++)
        {
            int u,v,dist;
            scanf("%d%d%d",&u,&v,&dist);
            e[u].push_back(node(v,dist));
        }
        for(int i=1;i<=n;i++) ans = max(ans,dfs(i));
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值