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 ...
随机推荐
- 【51NOD】斜率最大
[题解]通过画图易得结论:最大斜率一定出现在相邻两点之间. #include<cstdio> #include<algorithm> #include<cstring&g ...
- 【BZOJ】1486 [HNOI2009]最小圈
[算法]二分+spfa [题解]据说这个叫分数规划? 0-1分数规划 二分答案a,则对于任意的环有w/k≤a即w-ak≤0,若满足条件则a变小,否则a变大. 因为w=w1+w2+...+wk,所以变形 ...
- 深入理解微服务架构spring的各个知识点(面试必问知识点)
什么是spring spring是一个开源框架,spring为简化企业级开发而生,使用spring可以使简单的java bean 实现以前只有EJG才能实现的功能. Spring是一个轻量级的控制反转 ...
- 大聊Python----生产消费者模型
在并发编程中使用生产者和消费者模式能够解决绝大多数并发问题.该模式通过平衡生产线程和消费线程的工作能力来提高程序的整体处理数据的速度. 为什么要使用生产者和消费者模式? 在线程世界里,生产者就是生产数 ...
- 解决嵌套GridView显示不全的问题
package com.adan.selectcitydome.view; import android.content.Context; import android.util.AttributeS ...
- Android中的异常情况
1.setText()方法中,如果参数是int类型,Android会把它当做是一个id查找,报以下异常,因此解决办法就是将参数转化为String类型 如:setText(num) è setText( ...
- ACC026简要题解
这场AGC是时间正好在NOI之前休养生息的日子里,果断选择了放弃(虽然也从没有用大号打过).在随便做完了前几题之后就踏上了去长沙的旅程.NOI系列比赛总是休闲无比,咕咕不断,竟然连开幕式都能咕,今天A ...
- 64_g6
gsettings-desktop-schemas-devel-3.24.0-1.fc26.x..> 22-Mar-2017 20:46 19386 gsf-sharp-0.8.1-27.fc2 ...
- [How to] 使用Xib来创建view
1.简介 代码库 正如之前博客介绍的,xib可定义页面的某个部分,特别当此部分区域的view集中并且还有一些相互关联性(如隐藏等)是i特别适合使用xib来进行封装. 本文为[How to]使用自定义c ...
- MYSQL5.5源码安装 linux下
/* 首先安装必要的库 */ yum -y install gcc* ###### 安装 MYSQL ###### 首先安装camke 一.支持YUM,则 yum install -y cmake 二 ...