Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp
1 second
256 megabytes
standard input
standard output
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.
As usual, Alyona has some troubles and asks you to help.
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).
Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.
6 12
14
11 14
31
1 5
1
3 8
5
5 7
7
21 21
88
Following pairs are suitable in the first sample case:
for x = 1 fits y equal to 4 or 9;
- for x = 2 fits y equal to 3 or 8;
- for x = 3 fits y equal to 2, 7 or 12;
- for x = 4 fits y equal to 1, 6 or 11;
- for x = 5 fits y equal to 5 or 10;
- for x = 6 fits y equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case.
题意:给你 n,m 1 ≤ x ≤ n, 1 ≤ y ≤ m 问有多少对x/y 使得(x+y)%5==0
题解:水
#include <bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m;
int main()
{
scanf("%d %d",&n,&m);
ll ans=;
for(int i=;i<=n;i++)
{
int exm=i%;
int re=-exm;
if(m>=re){
ans=ans+(m-re)/;
ans++;
}
}
cout<<ans<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.
The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
5
1 3 3 3 6
5
2
2 1
3
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements.
题意:给你n个数 每次操作只能减小某个数 经过一系列操作之后 使得没有出现的数的最小值尽量大
题解:水
#include <bits/stdc++.h>
#define ll __int64
using namespace std;
int n;
int a[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
int now=;
for(int i=;i<=n;i++)
{
if(now<=a[i])
now++;
else
continue;
}
cout<<now<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > au, where au is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u.
Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root.
Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?
In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree.
In the second line the sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 109) is given, where ai is the number written on vertex i.
The next n - 1 lines describe tree edges: ith of them consists of two integers pi and ci (1 ≤ pi ≤ n, - 109 ≤ ci ≤ 109), meaning that there is an edge connecting vertices i + 1 and pi with number ci written on it.
Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.
9
88 22 83 14 95 91 98 53 11
3 24
7 -8
1 67
1 64
9 65
5 12
6 -80
3 8
5
The following image represents possible process of removing leaves from the tree:
题意:给你一个树 有点权 边权 删除最少的叶子结点 使得 对于任意一个点到其子树中的点的路径边权和小于等与目标点的点权
题解:dfs处理 记录当前节点的祖先节点中到当前节点的路径边权和的最大值
#include <bits/stdc++.h>
#define ll __int64
using namespace std;
ll n;
ll a[];
ll p[];
ll in[];
ll out[];
ll d[];
map<ll,ll> mp;
ll nedge=;
ll dfn=;
ll re=;
struct node
{
ll to;
ll pre;
ll we;
}N[];
void add(ll pre,ll to,ll we)
{
nedge++;
N[nedge].to=to;
N[nedge].we=we;
N[nedge].pre=p[pre];
p[pre]=nedge;
}
void getdfs(ll root,ll sum,ll now)
{
in[root]=++dfn;
d[root]=max(sum,now);
sum=d[root];
mp[root]=;
for(int i=p[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
getdfs(N[i].to,sum+N[i].we,N[i].we);
}
out[root]=dfn;
}
void dfs(ll root)
{
mp[root]=;
for(int i=p[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
if(d[N[i].to]>a[N[i].to])
{
re=re+out[N[i].to]-in[N[i].to]+;
continue ;
}
dfs(N[i].to);
}
}
int main()
{
ll r,w;
memset(p,,sizeof(p));
scanf("%I64d",&n);
for(ll i=;i<=n;i++)
scanf("%I64d",&a[i]);
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d",&r,&w);
add(i,r,w);
add(r,i,w);
}
getdfs(,0ll,0ll);
mp.clear();
dfs();
printf("%I64d\n",re);
return ;
}
Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp的更多相关文章
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化
E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given ...
- Codeforces Round #358 (Div. 2) D. Alyona and Strings dp
D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree 水题
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...
随机推荐
- JavaScript事件冒泡和捕获
事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件. 事件冒泡是自下而上的去触发事件. 绑定事件方法的第三个参数,就是控制事件触发顺序是否为事件捕获.true,事件捕获:fa ...
- socket发送文字、图片、文件---基于python实现
socket官方文档:https://docs.python.org/2/library/socket.html socket中文详细介绍:http://blog.csdn.net/rebelqsp/ ...
- php分页类学习
分页是目前在显示大量结果时所采用的最好的方式.有了下面这些代码的帮助,开发人员可以在多个页面中显示大量的数据.在互联网上,分页是一般用于搜索结果或是浏览全部信息(比如:一个论坛主题).几乎在每一个W ...
- c语言的知识与能力自评
知识与能力 C语言最早是由美国Bell实验室设计的,主要用作UNIX系统的工作语言,后来发展成为一种通用语言.C与UNIX有密切的关系,C最早是在PDP机器上用UNIX操作系统上开发的,后来又用C语言 ...
- [并查集] How Many Tables
题目描述 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants ...
- 软工网络15团队作业4——Alpha阶段敏捷冲刺-8
一.当天站立式会议照片: 二.项目进展 昨天已完成的工作: 服务器的完善,后端配置的修改. 明天计划完成的工作: 完善各个功能以及修改bug. 工作中遇到的困难: 服务器的语言编程困难,后端调试中不断 ...
- PHP 生成条形码
<?php class BarCode128 { const STARTA = 103; const STARTB = 104; const STARTC = 105; const STOP = ...
- linux svn启动和关闭
linux svn启动和关闭 博客分类: linux系统 svnlinux 1,启动SVN sudo svnserve -d -r /home/data/svn/ 其中 -d 表示守护进程, -r ...
- Fiddler绕过前端直接和后台进行交互
测试需求:有一个功能,允许用钻石兑换金币,假设1钻石=1金币,前端控制一次至少兑换10个,最多100个,后台不做验证. 测试方案:输入10,也就是告诉前端我要兑换10个金币,等前端验证通过之后,截取要 ...
- IE8 没有内容的盒子,如果有定位,浮现在其他盒子上 可能会有点击穿透没有作用的情况
IE8 没有内容的盒子,如果有定位,浮现在其他盒子上 可能会有点击穿透没有作用的情况