1. Banana

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 the second one records the types of bananas from different places.

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

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

Input Format

The first line contains an integer TT, indicating that there are TT test cases.

For each test case, the first line contains two integers NN and MM, representing the length of the first and the second lists respectively.

In the each line of following NN lines, two positive integers i, ji,j indicate that the ii-th monkey favours the jj-th type of banana.

In the each line of following MM lines, two positive integers j, kj,k indicate that the jj-th type of banana could be find in the kk-th place.

All integers of the input are less than or equal to 5050.

Output Format

For each test case, output all the pairs x, yx,ythat the xx-the monkey can accept at least one type of bananas from the yy-th place.

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

If two pairs own the same xx, output the one who has a smaller yy first.

And there should be an empty line after each test case.

样例输入

1
6 4
1 1
1 2
2 1
2 3
3 3
4 1
1 1
1 3
2 2
3 3

样例输出

1 1
1 2
1 3
2 1
2 3
3 3
4 1
4 3

题目来源

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

#include<stdio.h>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std; int main()
{
int t;
scanf("%d",&t);
while(t--){
int m,n,i,x,y,mm=,mi=;
vector<int>mon[],pla[],s;
scanf("%d%d",&m,&n);
for(i=;i<m;i++){
scanf("%d%d",&x,&y);
mon[x].push_back(y);
mm=max(mm,x);
mi=min(mi,x);
}
for(i=;i<n;i++){
scanf("%d%d",&x,&y);
pla[x].push_back(y);
}
int a[],k=,j,l;
for(i=mi;i<=mm;i++){
memset(a,,sizeof a);
for(j=;j<mon[i].size();j++){
for(l=;l<pla[mon[i][j]].size();l++){
a[pla[mon[i][j]][l]]=;
}
}
for(j=;j<;j++){
if(a[j])
printf("%d %d\n",i,j);
}
}
puts("");
}
}
  1. Coconut

Coconut is Captain Gangplank's favourite fruit. That is why he needs to drink coconut juice from bb coconuts each day.

On his next trip, he would pass through NNcitis.

His trip would begin in the 11-st city and end in the NN-th city.

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

Initially, there is no coconut on his ship. Fortunately, he could get supply of C_iC​i​​coconuts from the ii-th city.

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

Input Format

The first line contains an integer TT, indicating that there are TT test cases.

For each test case the first line contains two integers NN and bb as described above.

The second line contains NN integers C_1, C_2, \cdots, C_NC​1​​,C​2​​,⋯,C​N​​.

The third line contains N-1N−1 integers D_1, D_2, \cdots, D_{N-1}D​1​​,D​2​​,⋯,D​N−1​​.

All integers in the input are less than 10001000.

Output Format

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

样例输入

2
4 1
3 2 1 4
1 2 3
4 2
2 4 6 8
3 2 1

样例输出

Yes
No

题目来源

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

#include<stdio.h>
int main()
{
int a[],t,i,j,n,m,s,x,k;
scanf("%d",&t);
while(t--)
{
k=s=;
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(i=;i<n-;i++)
{
s+=a[i];
scanf("%d",&x);
s-=x*m;
if(s<)
{
k=;
continue;
}
}
if(k)puts("No");
else puts("Yes");
}
}
    1. Half-consecutive Numbers

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive.

For given NN, find the smallest rr which is no smaller than NN such that t_rt​r​​ is square.

Input Format

The input contains multiple test cases.

The first line of a multiple input is an integer TTfollowed by TT input lines.

Each line contains an integer N~(1\le N\le 10^{16})N (1≤N≤10​16​​).

Output Format

For each test case, output the case number first.

Then for given NN, output the smallest rr.

If this half-consecutive number does not exist, output -1−1.

样例输入

4
1
2
9
50

样例输出

Case #1: 1
Case #2: 8
Case #3: 49
Case #4: 288

题目来源

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

这几个数很少,打表找规律都行的

不过我读错了题意,这个锅我背

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[]={,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
};
int main()
{
ios::sync_with_stdio(false);
int T,k=;
scanf("%d",&T);
while(T--)
{
LL n;
scanf("%lld",&n);
int pos=lower_bound(a,a+,n)-a;
printf("Case #%d: %lld\n",k++,a[pos]);
}
return ;
}
    1. Islands

问答

只看题面

  • 31.41%
  • 1000ms
  • 131072K

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 from place to place.

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

Luckily, there are already MM sea routes.

All routes are one-way, and the ii-th route can transport person and goods from island u_iu​i​​ to v_iv​i​​.

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 increasing number 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 TT, indicating that there are TT test cases.

For each test case, the first line includes two integers N~(N \leq 10000)N (N≤10000) and M~(M \leq 100000)M (M≤100000), as described above.

After that there are MM lines. Each line contains two integers u_iu​i​​ and v_iv​i​​.

Output Format

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

样例输入

2
4 3
1 2
2 3
3 4
4 4
1 2
1 4
3 2
3 4

样例输出

1
2

题目来源

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

这个求lca的,找个模板就能a

#include<bits/stdc++.h>
#define N 100000+10
using namespace std;
vector<int>g[N];
int low[N],dfn[N],dfs_clock, sccon[N],scc_cnt;
bool instack[N];
stack<int>s;
int n,m;
void tarjan(int u,int fa)
{
int v;
low[u]=dfn[u]=++dfs_clock;
s.push(u);
instack[u]=true;
for(int i=;i<g[u].size();i++)
{
v=g[u][i];
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[u],low[v]);
}
else if(instack[v])
low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
scc_cnt++;
while()
{
v=s.top();
s.pop();
instack[v]=false;
sccon[v]=scc_cnt;
if(v==u)
break;
}
}
}
int in[N],out[N];
void soudian()
{
int i,j;
for(i=;i<=scc_cnt;i++)
in[i]=out[i]=;
for(i=;i<=n;i++)
{
for(j=;j<g[i].size();j++)
{
int u=sccon[i];
int v=sccon[g[i][j]];
if(u!=v)
{
out[u]++;
in[v]++;
}
}
}
}
int main()
{
int t,x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
g[i].clear();
while(m--)
{
scanf("%d%d",&x,&y);
g[x].push_back(y);
}
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(sccon,,sizeof(sccon));
memset(instack,false,sizeof(instack));
dfs_clock=scc_cnt=;
for(int i=;i<=n;i++)
if(!dfn[i])
tarjan(i,-);
soudian();
if(scc_cnt==)
{
printf("0\n");
continue;
}
int si=,so=;
for(int i=;i<=scc_cnt;i++)
{
if(in[i]==)
si++;
if(out[i]==)
so++;
}
printf("%d\n",max(si,so));
}
}
    1. Query on a string

问答

只看题面

  • 19.46%
  • 500ms
  • 131072K

You have two strings SS and TT in all capitals.

Now an efficient program is required to maintain a operation and support a query.

The operation C~i~chC i ch with given integer ii and capital letter chch, changes the ii-th character of SS into chch.

The query Q~i~jQ i j asks the program to find out, in the substring of SS from the ii-th character to the jj-th one, the total number of TT appearing.

Input Format

The first line contains an integer TT, indicating that there are TT test cases.

For each test case, the first line contains an integer N~(N \leq 100000)N (N≤100000).

The second line is the string S~(|S| \leq 100000)S (∣S∣≤100000) and the third line is the string T~(|T| \leq 10)T (∣T∣≤10).

Each of the following NN lines provide a operation or a query as above descriptions.

Output Format

For each query, output an integer correponding to the answer.

Output an empty line after each test case.

样例输入

1
5
AABBABA
AA
Q 1 3
C 6 A
Q 2 7
C 2 B
Q 1 5

样例输出

1
2
0

题目来源

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

这个题看起来挺简单的,大概就是区间修改区间查询

直接线段树就可以的,但是有些线段树的常数有点大,可以换个姿势比如树状数组水过的

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[];
#define NN 100010 struct node{
int l, r, cover;
int sum;
int key;
}st[NN * ]; long long f[NN + ]; void Init(int l, int r, int id){
st[id].l = l;
st[id].r = r;
st[id].cover = ;
st[id].key = ; if (r - l <= ){
st[id].cover = ;
st[id].sum = f[l];
return;
} int mid = (l + r) >> ; Init(l, mid, id * );
Init(mid, r, id * + );
st[id].sum = st[id * ].sum + st[id * + ].sum; //key1
} void Update(int l, int r, int key, int id){ //key2
if (st[id].l == l && st[id].r == r){
st[id].key += key;
st[id].cover = ;
return ;
}
st[id].sum += (r - l) * key; //key3
/* if (st[id].cover > 0){
st[id * 2].cover = 1;
st[id * 2 + 1].cover = 1;
st[id * 2].key += st[id].key;
st[id * 2 + 1].key += st[id].key;
st[id].cover = 0;
st[id].key = 0;
}*/
int mid = (st[id].l + st[id].r) >> ; if (r <= mid){
Update(l, r, key, id * );
}else if(l >= mid){
Update(l, r, key, id * + );
}else{
Update(l, mid, key, id * );
Update(mid, r, key, id * + );
}
} int Search(int l, int r, int id){
int ans = ;
//key4
if (st[id].cover > ){
ans += st[id].key * (r - l);
} //key5
if (st[id].l == l && st[id].r == r){
ans += st[id].sum;
return ans;
} int mid = (st[id].l + st[id].r) >> ; if (r <= mid){
return ans + Search(l, r, id * );
}else if(l >= mid){
return ans + Search(l, r, id * + );
}else{
return ans + Search(l, mid, id * ) + Search(mid, r, id * + );
}
}
int main()
{
int t,i,j,s,x,r,m,n,y,k;
char c[],b[],e[];
scanf("%d",&t);
while(t--)
{
memset(f,,sizeof(f));
scanf("%d",&n);
scanf("%s%s",a,b);
r=strlen(a);
m=strlen(b);
for(i=;i+m-<r;i++)
{
for(j=;j<m;j++)
{
if(a[i+j]!=b[j])
break;
}
if(j==m)f[i]=;
}
Init(,r,);
//printf("%d\n",s);
while(n--)
{
scanf("%s",c);
if(c[]=='Q')
{
scanf("%d%d",&x,&y);
if(y-x+<m)s=;
else s=Search(x-,y-m+,);
printf("%d\n",s);
}
else if(c[]=='C')
{
scanf("%d%s",&x,e);
a[x-]=e[];
if(x-m<)i=;
else i=x-m;
for(;i<x&&i+m-<r;i++)
{
for(j=;j<m;j++)
{
if(a[i+j]!=b[j])
break;
}
if(f[i]==&&j==m||f[i]==&&j!=m)
continue;
int u=i+;
if(j!=m)
{
f[i]=;
Update(u-,u,-,);
}
if(j==m)
{
f[i]=;
Update(u-,u,,);
}
}
}
}
puts("");
}
}
    1. Skiing

问答

只看题面

  • 23.59%
  • 1000ms
  • 131072K

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

This ski resort has MM different ski paths and NN different flags situated at those turning points.

The ii-th path from the S_iS​i​​-th flag to the T_iT​i​​-th flag has length L_iL​i​​.

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 the paths, 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 TT, indicating that there are TT cases.

In each test case, the first line contains two integers NN and MM where 0 < N \leq 100000<N≤10000and 0 < M \leq 1000000<M≤100000 as described above.

Each of the following MM lines contains three integers S_iS​i​​, T_iT​i​​, and L_i~(0 < L_i < 1000)L​i​​ (0<L​i​​<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.

样例输入

1
5 4
1 3 3
2 3 4
3 4 1
3 5 2

样例输出

6

题目来源

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

最长路,继续dfs维护

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
struct edge
{
int to,w;
};
vector<edge>G[N];
ll dis[N];
ll dfs(int u)
{
if(dis[u])return dis[u];
ll res=;
for(int i=;i<(int)G[u].size();i++)
{
res=max(res,dfs(G[u][i].to)+G[u][i].w);
}
return dis[u]=res;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
G[i].clear();
for(int i=;i<=m;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[u].push_back({v,w});
}
ll ans=;
memset(dis,,sizeof(ll)*(n+));
for(int i=;i<=n;i++)
{
ans=max(dfs(i),ans);
}
printf("%lld\n",ans);
}
return ;
}

2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛的更多相关文章

  1. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  2. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)

    参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...

  3. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】

    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛  M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...

  4. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  5. ICPC 2018 徐州赛区网络赛

    ACM-ICPC 2018 徐州赛区网络赛  去年博客记录过这场比赛经历:该死的水题  一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进.     D. Easy Math 题意:   ...

  6. 【2017 ACM/ICPC 乌鲁木齐赛区网络赛环境测试赛 E】蒜头君的排序

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 莫队算法+树状数组. 区间增加1或减少1. 对逆序对的影响是固定的. (用冒泡排序变成升序的交换次数,就是逆序对的个数) [错的次数] 0 [ ...

  7. 2017 乌鲁木齐赛区网络赛 J Our Journey of Dalian Ends 费用流

    题目描述: Life is a journey, and the road we travel has twists and turns, which sometimes lead us to une ...

  8. [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题

    第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...

  9. 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit    1000 ms Memory li ...

  10. 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!

    鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Fo ...

随机推荐

  1. 前端之CSS字体和文本类属性

    一.字体类属性: 1.字体类型: font-family:字体1,字体2,字体3; 常用写法: font-family:"微软雅黑",Arial; 注:a) 多个字体之间用逗号分隔 ...

  2. JavaScript中的this陷阱

    当有人问起你JavaScript有什么特点的时候,你可能立马就想到了单线程.事件驱动.面向对象等一堆词语,但是如果真的让你解释一下这些概念,可能真解释不清楚.有句话这么说:如果你不能向一个6岁小孩解释 ...

  3. 解析 MFC 中的 FromHandle

    MFC 对 Windows API 进行了封装,在很多方面都会提供便利.用 FromHandle 返回零时对象的指针,就可以调用各种类的方法.临时对象会在 OnIdle 中销毁.这里对 FromHan ...

  4. Visual SVN IIS反向代理设置

    需要解决的问题: 1. 设置反向代理 2. 解决部分后缀文件无法提交的问题 1. 设置反向代理 接收所有的URL 允许所有的HTTP_HOST 跳转到被代理的服务器 2. 允许所有后缀的文件访问IIS ...

  5. PL/SQL学习笔记(二)

    select * from protype;select * from product;---笛卡尔连接查询(交叉连接)select * from protype,product;select * f ...

  6. ipsec配置strongswan.conf和ipsec.conf

    配置strongswan.conf vi /usr/local/etc/strongswan.conf # strongswan.conf - strongSwan configuration fil ...

  7. Servlet The Request

    The Request HTTP Protocol Parameters 所有的HTTP Protocol Parameters都会放在一个Map中, 可以通过getParameterMap得到. 对 ...

  8. sparkmlib-相关系数

    一.基本原理 在stat包中实现了皮尔逊(Pearson)与 斯皮尔曼(Spearman)两类相关系数的计算 (1)Pearson:   (x,y)协方差/[(x标准方差)*(y标准方差)] 详情可以 ...

  9. Webpack2 视频教程

      原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」.Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本 ...

  10. webpack之postcss集成

    项目 为了 兼容各个浏览器,需要加各种 c3前缀,如果手动的加肯定 相对比较麻烦,但是现在有webpack,gulp之类的 工具可以自动给我们加上,可以说效率上加速不少.如果 配置中 做个happyp ...