2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
- 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
题目来源
#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("");
}
}
- 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_iDi days.
Initially, there is no coconut on his ship. Fortunately, he could get supply of C_iCicoconuts 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_NC1,C2,⋯,CN.
The third line contains N-1N−1 integers D_1, D_2, \cdots, D_{N-1}D1,D2,⋯,DN−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
题目来源
#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");
}
}
- Half-consecutive Numbers
The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545and t_i=\frac{1}{2}i(i+1)ti=21i(i+1), are called half-consecutive.
For given NN, find the smallest rr which is no smaller than NN such that t_rtr 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≤1016).
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
题目来源
这几个数很少,打表找规律都行的
不过我读错了题意,这个锅我背
#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 ;
}
- 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_iui to v_ivi.
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_iui and v_ivi.
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
题目来源
这个求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));
}
}
- 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
题目来源
这个题看起来挺简单的,大概就是区间修改区间查询
直接线段树就可以的,但是有些线段树的常数有点大,可以换个姿势比如树状数组水过的
#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("");
}
}
- 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_iSi-th flag to the T_iTi-th flag has length L_iLi.
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_iSi, T_iTi, and L_i~(0 < L_i < 1000)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.
样例输入
1
5 4
1 3 3
2 3 4
3 4 1
3 5 2
样例输出
6
题目来源
最长路,继续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 亚洲区(乌鲁木齐赛区)网络赛的更多相关文章
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)
参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...
- 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 ...
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- 【2017 ACM/ICPC 乌鲁木齐赛区网络赛环境测试赛 E】蒜头君的排序
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 莫队算法+树状数组. 区间增加1或减少1. 对逆序对的影响是固定的. (用冒泡排序变成升序的交换次数,就是逆序对的个数) [错的次数] 0 [ ...
- 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 ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!
鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS Memory Limit:262144KB 64bit IO Fo ...
随机推荐
- poj1717
两次记忆化搜索,第一次找最小的gap,第二次找最少的次数. #include <iostream> #include <cstdio> #include <cstring ...
- IE6下png背景不透明——张鑫旭博客读书笔记
从今天开始跟着大牛张鑫旭的步伐,每天进步一点点 问题:IE6不支持png背景透明或半透明 一.可解决的方法 补充:css滤镜主要是用来实现图像的各种特殊效果.(了解) css滤镜的标识符是“filte ...
- 自动完成文本框(AutoCompleteTextView与MultiAutoCompleteTextView)关联适配器
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
- Android项目中包名的修改
通常修改包名时会造成R文件错误,并且有时带有原因不明的Manifest文件中多处文本混乱. 所以,将目前认为最为简洁方便的修改包名流程记录如下: 假设我们目前的包名为com.pepper.util,我 ...
- 查询 request 对象的数据
在 EmpController 中调用 RequestInfoService ris = new RequestInfoService(); ris.saveRequestInfo(request); ...
- TLint for 虎扑体育应用源码项目
虎扑非官方客户端TLint全新Material Design设计,简洁美观支持论坛全部操作,浏览帖子.点亮.回复.引用.收藏等多项个性化设置(不同主题,不同阅读模式) TLint For 虎扑体育 更 ...
- 单源最短路Dijstra
#include<iostream> #include<cstring> #define INF 0x3f3f3f3f using namespace std; ][],d[] ...
- python已安装好第三方库,pycharm import时仍标红的解决办法
pip install pymysql之后导入import pymysql时候标红 发现 pymysql下方还是标红,不能正常导入 可以试用一下以下的办法 解决办法: 首先打开 Settings找到P ...
- vsftp配置日志及其启用本地时间
vsftp配置日志及其启用本地时间 1. 启用vsftp日志 xferlog_enable=YES xferlog_std_format=YES xferlog_file=/var/log/xferl ...
- WinPcap过滤串表达式的语法
注意:这篇文档取自tcpdump的指南.原始的版本 www.tcpdump.org 找到. wpcap的过滤器是以已声明的谓词语法为基础的.过滤器是一个ASCII字符串,它包含了一个过滤表达式.p ...