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. Java编程基础-变量

    1.变量的定义. 变量与常量相对应,变量是在程序运行过程中它的值允许改变的量,变量可以通过变量名访问. 2.Java中的三大变量 (1).类变量.又称为静态变量,在类中定义类的属性时,使用static ...

  2. ES-windos环搭建-ik中文分词器

    ik下载 打开Github官网,搜索elasticsearch-analysis-ik,单击medcl/elasticsearch-analysis-ik.或者直接点击 在readme.md文件中,下 ...

  3. 从零开始利用vue-cli搭建简单音乐网站(二)

    1.利用vue-router实现页面跳转 程序可以正常运行之后,下面我们需要配置路由实现页面的局部刷新,这一功能将用来实现网站页面的跳转. 打开程序目录,进入"src\router\inde ...

  4. Android 两个ArrayList找出相同元素及单个ArrayList删除元素

    //从一个ArrayList中删除重复元素 List<String> arrayList1 = new ArrayList<String>(); arrayList1.add( ...

  5. Linux shell例子

    #!/bin/bash read -p "input a dight:"echo $REPLY DATE=`date`echo "DATE is ${DATE}" ...

  6. LR中操中MySQL脚本模板

    Action(){ char chQuery[128]; MYSQL *Mconn; int result; //引入mysql动态链接库 lr_load_dll("libmysql.dll ...

  7. snprintf()返回值的陷阱

    int snprintf(char *restrict buf, size_t n, const char * restrict  format, ...); 函数说明:最多从源串中拷贝n-1个字符到 ...

  8. PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)

    PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...

  9. 拼凑json的实例

    一,拼凑  json 串 并传到后台 function writeToJson(num){ var i = 1; var jsonData = "["; for(i=1;i< ...

  10. shell脚本,如何写进度条。

    [root@localhost ~]# cat jindutiao.sh #!/bin/bash #进度条 n=$((/)) N=$((/)) ` do sleep 0.01 [ $(($i%$n)) ...