[Noip模拟题]砍树
来源:互联网 发布:电脑怎么用手机网络 编辑:程序博客网 时间:2024/05/28 15:06
Description
小A在一条水平的马路上种了
Input
第一行一个正整数
接下来n行,每行两个正整数
Output
输出一个数,表示最少砍断多少长度。
Sample Input
3
0 2
1 2
3 3
Sample Output
3
HINT
思路
一棵树
代码
#include <cstdio>#include <cstring>#include <algorithm>const int maxn=10000;int h[maxn+10],n,ans;int main(){ memset(h,255,sizeof h); scanf("%d",&n); for(int i=1; i<=n; i++) { int a,b; scanf("%d%d",&a,&b); if(h[a]!=-1) { ans+=h[a]+b; h[a]=0; } else { h[a]=b; } } for(int i=0; i<=maxn; i++) { int r=h[i]; if(h[i]!=-1) { for(int j=std::max(i-h[i],0); j<=std::min(i+h[i],maxn); j++) { if((h[j]!=-1)&&(j!=i)) { r=std::min(r,abs(j-i)); } } } ans+=h[i]-r; } printf("%d\n",ans); return 0;}
阅读全文
1 0
- [Noip模拟题]砍树
- NOIP模拟题
- 【lcyz】noip模拟题
- NOIP模拟题题解
- 【NOIP模拟题】最大公约数
- 【NOIP模拟题】连通
- 【noip模拟题】数列
- NOIP模拟题 NBA
- NOIP模拟题:数字
- noip模拟题10.20
- NOIP模拟题 10.31
- noip模拟题 11.2
- noip模拟题11.5
- noip模拟题11.7
- noip模拟题11.8
- noip模拟题11.9
- noip模拟题11.12
- [Noip模拟题]寿司
- 用户禁止cookie后,如何继续使用session
- 有哪些目前流行的前端框架
- Android Html设置TextView的颜色、加粗样式
- PowerDesigner16 时序图
- Java从在数组中删除指定元素
- [Noip模拟题]砍树
- POJ 3422 Kaka's Matrix Travels 费用流(用过后变成0的处理)
- Django
- QNX常用调试命令-QNX常用命令
- ListView嵌套EditText处理
- Centos下安装Percona-toolkit
- 为什么会得肺癌,得了肺癌怎么治?
- JVM中的域名解析缓存
- SQL Server 使用 Powershell 备份数据库