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 ...
随机推荐
- 基本控件文档-UISegment属性----iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...
- linux 3389连接工具Rdesktop
简单使用 工作机换成战斗机了,改用ubuntu,原来的windows7上东西笔记多,还不想重装.用rdesktop来远程连接windows: sudo apt-get install rdesktop ...
- Python学习笔记 - day12 - Python操作NoSQL
NoSQL(非关系型数据库) NoSQL,指的是非关系型的数据库.NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称.用于超大规模数据的存储.(例如 ...
- [Leetcode Week12]Unique Paths
Unique Paths 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/unique-paths/description/ Description A ...
- git - 开发者电脑与服务器的配置
首先公司要有一台git服务器,现在一般都托管在github服务器上,在中国可能会托管到oschina上,oschina有一点好处就是可以免费托管私有项目,而在github上想要托管自己的项目是收费的, ...
- [New learn] 网络基础-网络操作
代码:https://github.com/xufeng79x/NETOperation 1.简介 主要记录基本的网络操作步骤,get/post关系和区别和文件上传实现. 2.准备 需要服务器端,如果 ...
- hihocoder 1178 : 计数
#1178 : 计数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物, ...
- 最佳 WordPress 静态缓存插件 WP Super Cache 安装和使用(转)
WP Super Cache 是 WordPress 官方开发人员 Donncha开发,是当前最高效也是最灵活的 WordPress 静态缓存插件.它把整个网页直接生成 HTML 文件,这样 Web ...
- maven项目的pom.xml文件详解
<project xmlns="http://maven.apache.org/POM/4.0.0 " 2 xmlns:xsi="http://www.w3.org ...
- gulp配合vue压缩代码格式化
实际项目就是一个单页面.因此,我觉得用gulp足够,并且不需要webpack和vue-cli因为没有必要使用组件. 先来说一下项目结构 1. 然后来看看我的包管理package.json都用了啥,你也 ...