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 ...
随机推荐
- 解决vue代码缩进报错问题 关闭ESlint
前言 使用vue-cli来构建单页SPA应用,提示代码缩进报错 原因分析 通过查看package.json文件我们可以发现,在文件中默认安装了eslint-loader模块,eslint-loader ...
- linux启动过程——(三)
- linux下进行base64编码解码
1.编码 2.解码
- Java的四种引用——强弱软虚
1.强引用—用new 当我们用new向堆区申请一片内存空间时,此时就是强引用. 当内存不足,GC(垃圾收集器)不会回收该强引用的对象. 2.软引用—用SofeReference类实现 用来描述一些还有 ...
- Pythone3 sys模块
1.sys.argv 可以实现从程序外部向程序传递参数2.sys.exit() 程序中间退出,exit(0)正常退出,其他为异常退出3.sys.getdefaultencoding() 获取系统编码方 ...
- libSVM笔记之(一)在matlab环境下安装配置libSVM
本文为原创作品,转载请注明出处 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.cnblogs.com/xujianqing 台湾林智仁教 ...
- 哈希表(一):解决hash冲突的几种方法
(一)线性探测法 线性探测法是最简单的处理冲突的方法. (1)插入元素:插入元素时,如果发生冲突,算法将从该槽位向后遍历哈希表,直到找到表中的下一个空槽,并将该值放入到空槽当中. (2)查找元素:查找 ...
- TCP之listen&backlog
1. listen函数: #include <sys/socket.h> int listen(int sockfd, int backlog); ret-成功返回0 失败返回- list ...
- java===字符串常用API介绍(转)
本文转自:http://blog.csdn.net/crazy_kid_hnf/article/details/55102861 字符串基本操作 1.substring(from,end)(含头不含尾 ...
- python基础===中文手册,可查询各个模块
http://python.usyiyi.cn/translate/python_352/index.html