2017icpc 乌鲁木齐网络赛
A .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,y that 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
签到,写两个map记录每个产地有哪几种水果,每个猴子喜欢哪种水果,双重for一下,第三重用map迭代器迭代下各产地的各个水果种类是否能有对应猴子喜欢就行。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
map<int,bool>::iterator it;
int main()
{
int n,m,T,u,v;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
map<int,bool> a[],b[];
for(int i=;i<=n;i++)
{
scanf("%d%d",&u,&v);
a[u][v]=;
}
for(int j=;j<=m;j++)
{
scanf("%d%d",&u,&v);
b[v][u]=;
}
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(it=b[j].begin();it!=b[j].end();it++)
{
if(a[i].find(it->first)!=a[i].end())
{
printf("%d %d\n",i,j);
break;
}
}
}
}
printf("\n");
}
return ;
}
C.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 NN citis.
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
水题,for一遍就好了。
#include <bits/stdc++.h>
using namespace std; int sum[]; int main() {
int n, b;
int t;
scanf("%d", &t);
while(t --) {
scanf("%d%d", &n, &b);
memset(sum, , sizeof(sum));
for(int i = ; i <= n; ++ i) {
int x;
scanf("%d", &x);
sum[i] = sum[i-] + x;
}
int a = ;
bool ok = true;
for(int i = ; i <= n; ++ i) {
int x;
scanf("%d", &x);
a += x*b;
if(sum[i-] < a) {
ok = false;
}
}
if(ok) {
puts("Yes");
}
else {
puts("No");
}
}
return ;
}
E. Half-consecutive Numbers
emmm就是打个表找找规律再打个更大的表的事情嘛~,如果嫌麻烦直接上eois233333。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
LL a[]={ , , , , , , , , , , , , , , , , , , , , , , };
int main()
{
int T;
LL n;
scanf("%d",&T);
for(int kase=;kase<=T;kase++)
{
scanf("%lld",&n);
for(int i=;i<;i++)
if(a[i]>=n)
{
printf("Case #%d: %lld\n",kase,a[i]);
break;
}
}
return ;
}
F. Islands
是道图论题- -,没有找到题面。队友写的我就不写题解了。
#include <iostream>
#include <cstring>
#include <cstdio>
#define MAXN 100010
#define MAXE 100010
using namespace std;
int head[MAXN],tot1,tot2;
struct Edge{
int u,v,next;
}e1[MAXE],e2[MAXN];
void addEdge(int u,int v,Edge* edge,int& tol){
edge[tol].u=u;edge[tol].v=v;
edge[tol].next=head[u];head[u]=tol++;
}
int n,m;
int low[MAXN],dfn[MAXN],stack[MAXN],belong[MAXN],num[MAXN];
bool instack[MAXN];
int scc,top,Index;
void Tarjan(int u){
int v;
low[u]=dfn[u]=++Index;
stack[top++]=u;
instack[u]=true;
for(int i=head[u];i!=-;i=e1[i].next){
v=e1[i].v;
if(!dfn[v]){
Tarjan(v);
if(low[u]>low[v]) low[u]=low[v];
}
else if(instack[v]&&low[u]>dfn[v])
low[u]=dfn[v];
}
if(low[u]==dfn[u]){
++scc;
do{
v=stack[--top];
instack[v]=false;
belong[v]=scc;
num[scc]++;
}while(u!=v);
}
}
int inde[MAXN],outde[MAXN];
void solve(){
memset(dfn,,sizeof(dfn));
memset(instack,false,sizeof(instack));
memset(num,,sizeof(num));
scc=top=Index=;
for(int i=;i<=n;++i)
if(!dfn[i]) Tarjan(i);
tot2=;memset(head,-,sizeof(head));
memset(inde,,sizeof(inde));
memset(outde,,sizeof(outde));
int u,v;
for(int i=;i<m;++i){
u=belong[e1[i].u];
v=belong[e1[i].v];
if(u!=v){
addEdge(u,v,e2,tot2);
inde[v]++;
outde[u]++;
}
}
int a=,b=;
for(int i=;i<=scc;++i){
if(!inde[i]) a++;
if(!outde[i]) b++;
}
if(scc==)printf("0\n");///特殊情况当图本身为强联通图时,输出0
else
printf("%d\n",max(a,b));
}
int main()
{
int T;
scanf("%d\n",&T);
while(T--){
scanf("%d%d",&n,&m);
tot1=;memset(head,-,sizeof(head));
int u,v;
for(int i=;i<m;++i){
scanf("%d%d",&u,&v);
addEdge(u,v,e1,tot1);
}
solve();
}
return ;
}
G. Query on a string
题目大意
给一个字符串S(长度最大100000)和T(最长10) 
给出n次操作,一共有两种操作:
- Q i j :计算S中区间[i,j]中有多少个子区间能和T匹配
- C x ch :将S[x]变成字符c
S中每个字符开头的|T|长度的字符串若是T串则为1,不是则为0。用vis数组记录,并且树状数组记录vis的前缀和。
预处理暴力匹配求vis数组和前缀和,一遇到不匹配的就break掉。
修改的话就检查包含修改位置的字符串上开头位置字符串是否和T匹配就好了。询问直接树状数组求和。
我可能因为边界问题T了。。看了网上AC代码跟我差不多。。我就明白我是边界的问题了。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
using namespace std;
const int N=1e5+;
char s[N],t[N];
int bit[N];
bool vis[N];
int n,m,T,u,v,lens,lent;
char c,cc;
bool flag;
void add(int i,int x)
{
while(i<=lens)
{
bit[i]+=x;
i+= i & -i;
}
return ;
}
int sum(int i)
{
int s=;
while(i>)
{
s+=bit[i];
i-=i & -i;
}
return s;
}
int main()
{
scanf("%d",&T);
while(T--)
{
clr(bit);
clr(vis);
scanf("%d",&n);
scanf("%s",s+);
scanf("%s",t+);
lens=strlen(s+);
lent=strlen(t+);
for(int i=;i<=lens-lent+;i++)
{
flag=;
for(int j=;j<=lent;j++)
if(s[i+j-]!=t[j])
{
flag=;
break;
}
if(!flag)
{
add(i,);
vis[i]=;
}
}
for(int i=;i<=n;i++)
{
scanf(" %c",&c);
if(c=='Q')
{
scanf("%d%d",&u,&v);
if(v-lent+>u-)
printf("%d\n",sum(v-lent+)-sum(u-));
else
printf("0\n");
}
if(c=='C')
{
scanf("%d %c",&u,&cc);
swap(cc,s[u]);
for(int j=max(u-lent+,);j<=min(u,lens-lent+);j++)
{
if(vis[j]==)
{
if(cc!=s[u])
{
vis[j]=;
add(j,-);
}
}
else
{
flag=;
for(int k=;k<=lent;k++)
if(s[j+k-]!=t[k])
{
flag=;
break;
}
if(!flag)
{
add(j,);
vis[j]=;
}
}
}
}
}
printf("\n");
}
return ;
}
H: Skiing
time limit 1000ms memory limit 131072KB
 
i i
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 turning points. The i-th path from the S -th flag to the T -th flag has length L . 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 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 S , T , and L  (0 < L < 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. Sample Input
1 5 4 1 3 3 2 3 4 3 4 1 3 5 2
Sample Output
6
emmm就是找个最长路嘛- -,写个dfs+dp就行了0 0
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 10005 struct edeg{
int u, w, pre;
}; int dp[N];
int h[N];
edeg e[N*];
bool vis[N]; int DFS(int u);
void slove();
void init(){
memset(dp, -, sizeof(dp));
memset(h, -, sizeof(h)); } int main() {
int t;
scanf("%d", &t);
while(t --) {
slove();
}
return ;
} int DFS(int u) {
if(dp[u] != -) return dp[u];
if(h[u] == -) return ;
for(int i = h[u]; ~i; i = e[i].pre) {
dp[u] = max(dp[u], DFS(e[i].u)+e[i].w);
}
return dp[u];
} void slove(){
int res = ;
init();
int n, m;
int x, y, w;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++ i) {
scanf("%d%d%d", &x, &y, &w);
e[i] = edeg{y, w, h[x]};
h[x] = i;
}
for(int i = ; i <= n; ++ i) {
if(h[i] != -) {
dp[i] = DFS(i);
res = max(dp[i], res);
}
}
printf("%d\n", res);
}
菜校弱队在E题上卡了很久,然后又G胡改KMP最后还是没有发现边界有问题,止步于5题无缘去新疆吃哈密瓜了QAQ。
虽然6题也无缘233333。
很气,叉腰。
2017icpc 乌鲁木齐网络赛的更多相关文章
- 2017icpc乌鲁木齐网络赛Colored Graph (构造)
		题目 https://nanti.jisuanke.com/t/16958 题意 给定一个n(n<=500)个点的无向图,给每条边黑白染色,输出同色三角形最少的个数和对应的方案 分析 首先考虑给 ... 
- 2017乌鲁木齐网络赛 j 题
		题目连接 : https://nanti.jisuanke.com/t/A1256 Life is a journey, and the road we travel has twists and t ... 
- Our Journey of Dalian Ends 乌鲁木齐网络赛 最小费用最大流
		Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpecte ... 
- 2017乌鲁木齐网络赛 J题 Our Journey of Dalian Ends ( 最小费用最大流 )
		题目链接 题意 : 给出一副图,大连是起点,终点是西安,要求你求出从起点到终点且经过中转点上海的最小花费是多少? 分析 : 最短路是最小费用最大流的一个特例,所以有些包含中转限制或者经过点次数有限制的 ... 
- 2017ICPC沈阳网络赛 HDU 6201 -- transaction transaction transaction(树上dp)
		transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ... 
- 2017ICPC沈阳网络赛  HDU 6205 -- card card card(最大子段和)
		card card card Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ... 
- 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)
		题目描述 Two out-of-control cars crashed within about a half-hour Wednesday afternoon on Deer Park Avenu ... 
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
		Banana Bananas are the favoured food of monkeys. In the forest, there is a Banana Company that provi ... 
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛  H Skiing【拓扑排序,关键路径】
		2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H Skiing In this winter holiday, Bob has a plan for skiing at the moun ... 
随机推荐
- 作为一名前端开发工程师,你必须掌握的WEB模板引擎:Handlebars
			作为一名前端开发工程师,你必须掌握的WEB模板引擎:Handlebars 一.为什么需要使用模板引擎? 关于为什么要使用模板引擎,按照我常对学生说的一句话就是:不用重复造轮子.. 简单来说,模板最 ... 
- Vue 定义组件模板的七种方式(一般用单文件组件更好)
			在 Vue 中定义一个组件模板,至少有七种不同的方式(或许还有其它我不知道的方式): 字符串 模板字面量 x-template 内联模板 render 函数 JSF 单文件组件 在这篇文章中,我将通过 ... 
- SpringCloud Fegin超时重试源码
			springCloud中最重要的就是微服务之间的调用,因为网络延迟或者调用超时会直接导致程序异常,因此超时的配置及处理就至关重要. 在开发过程中被调用的微服务打断点发现会又多次重试的情况,测试环境有的 ... 
- javascript中=、==与===的区别
			1.等号 =赋值运算符,给变量赋值 var a="1"; 2.相等和不相等操作符 相等操作符由==表示,若两个操作数相等,则返回true:不相等操作符由!=表示,若两个操作数不相等 ... 
- 网络知识===wireshark抓包数据分析(一)
			wireshark分析: 上图是我进行一个HTTP协议的下载,文件内容大概是1.7M左右. 抓包数据: https://files.cnblogs.com/files/botoo/wireshark% ... 
- 【学习笔记】动态树Link-Cut-Tree
			这是两个月前写的,看能不能搬运过来…… 动态树是一类维护森林连通性的问题(已纠正,感谢ZQC巨佬),目前最(wo)常(zhi)见(hui)的动态树就是LCT(Link-Cut-Tree),然而LCT似 ... 
- popup menu案例,无说明只代码
			效果图: 布局文件, 展示列表的容器 <?xml version="1.0" encoding="utf-8"?> <LinearLayout ... 
- ACE_INET_Addr类 API
			ACE_INET_Addr类,在这个ACE_网络框架中,应该是比较重要的辅助类,该类主要封装了C SOCKET 的地址对象,通过外观封装的模式,把struct sockaddr_in封装在内.方便用户 ... 
- .net设置浏览器的文本模式
			这段时间做个项目,做的时候因为之前习惯了Google的调试方式,所以就一直在google上面调试,今天项目成员大家的部分要整合,就放到ie8下面测试,但是遇到一个问题,就是用ie打开之后文本模式一直是 ... 
- Aspxgridview 根据条件来自定义计算Totalsummery
			protected void ASPxGridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEven ... 
