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.

样例输入


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.

样例输入


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次操作,一共有两种操作:

    1. Q i j :计算S中区间[i,j]中有多少个子区间能和T匹配
    2. 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 乌鲁木齐网络赛的更多相关文章

  1. 2017icpc乌鲁木齐网络赛Colored Graph (构造)

    题目 https://nanti.jisuanke.com/t/16958 题意 给定一个n(n<=500)个点的无向图,给每条边黑白染色,输出同色三角形最少的个数和对应的方案 分析 首先考虑给 ...

  2. 2017乌鲁木齐网络赛 j 题

    题目连接 : https://nanti.jisuanke.com/t/A1256 Life is a journey, and the road we travel has twists and t ...

  3. Our Journey of Dalian Ends 乌鲁木齐网络赛 最小费用最大流

    Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpecte ...

  4. 2017乌鲁木齐网络赛 J题 Our Journey of Dalian Ends ( 最小费用最大流 )

    题目链接 题意 : 给出一副图,大连是起点,终点是西安,要求你求出从起点到终点且经过中转点上海的最小花费是多少? 分析 : 最短路是最小费用最大流的一个特例,所以有些包含中转限制或者经过点次数有限制的 ...

  5. 2017ICPC沈阳网络赛 HDU 6201 -- transaction transaction transaction(树上dp)

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  6. 2017ICPC沈阳网络赛 HDU 6205 -- card card card(最大子段和)

    card card card Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. 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 ...

  8. 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛

    Banana Bananas are the favoured food of monkeys. In the forest, there is a Banana Company that provi ...

  9. 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H Skiing【拓扑排序,关键路径】

    2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛  H Skiing In this winter holiday, Bob has a plan for skiing at the moun ...

随机推荐

  1. hibernate单列的多值查询

    比如你的表主键是id,你要删除id 是 34,56,99 这样的.. uid是拼好的 比如 '34','56','99' ,以前我会这样写 String queryString = "upd ...

  2. 【洛谷 P3628】 [APIO2010]特别行动队 (斜率优化)

    题目链接 斜率优化总结待补,请催更.不催更不补 \[f[i]=f[j]+a*(sum[i]-sum[j])^2+b*(sum[i]-sum[j])+c\] \[=f[j]+a*sum[i]^2+a*s ...

  3. python实战===国内很简单实用的一些开源的api以及开源项目

    原创 2017年03月25日 15:40:59 标签: api / 开源项目 / app / 免费接口   声明 以下所有 API 均由产品公司自身提供,本人皆从网络获取.获取与共享之行为或有侵犯产品 ...

  4. tornado样板

    python tornado  样版 (包含出错页面) 2018-02-27  13:07:30 1 # -*- coding:utf-8 -*- 2 3 import tornado.web 4 i ...

  5. ASP.NET Core学习链接

    https://www.cnblogs.com/artech/p/dependency-injection-in-asp-net-core.html http://www.cnblogs.com/ar ...

  6. 应用程序有bug崩溃重启的案例2

    ------解决思路----------------------另外做一个服务或者程序定时监控系统进程.程序奔溃的话,都会在入口函数出现异常处理一下winform可以有两个事件来捕获主线程异常和线程异 ...

  7. powershell常用操作

    创建文件 New-Item -path $file_path -itemtype file 创建目录 New-Item -path $dir_path -type directory 删除目录 Rem ...

  8. JAVA二叉树的创建以及各种功能的实现

    直接上代码了,代码说得很清楚了 package BTree; public class BTree { private Node root; private class Node { private ...

  9. python写的的简单的爬虫小程序

    import re import urllib def getHtml(url): page=urllib.urlopen(url) html=page.read() return html def ...

  10. 【转】Mac系统新建txt文本文件技巧

    很多时候,我们需要在 Mac 中创建 txt 文件来记录一些信息,但是打开系统自带的文本编辑默认并不是创建 txt 文本文件 方法一: 打开终端,cd 到想要创建 txt 文本文件的目录(如桌面) 1 ...