POJ 2665

 1 #include<iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4
 5 int main()
 6 {
 7     //freopen("acm.acm","r",stdin);
 8     int tree;
 9     int num;
10     int sum;
11     int a,b;
12     while(1)
13     {
14     cin>>tree;
15     cin>>num;
16     if(!tree && !num)
17         break;
18     ++ tree;
19     sum = 0;
20     while(num --)
21     {
22         cin>>a;
23         cin>>b;
24         sum += b - a + 1;
25     }
26     cout<<tree - sum<<endl;
27     }
28 }
时间: 2024-08-30 13:04:14

POJ 2665的相关文章

POJ 2665 Trees

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10075   Accepted: 6622 Description The road off the east gate of Peking University used to be decorated with a lot of trees. However, because of the construction of a subway, a lot of them

POJ 2665 Trees(水题)

[题意简述]:就是有一段路上有和长度加一的值相等的数目,现在要在这条路上修路,所以要砍掉一些树,问剩下了多少树. [分析]:很简单,注意一的处理就好. //216K 79Ms #include<iostream> using namespace std; int main() { int len,n,s,e; while(cin>>len>>n) { int sum = 0; if(len == 0&&n == 0) break; for(int i =

POJ 2104&amp;HDU 2665 Kth number(主席树入门+离散化)

K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 50247   Accepted: 17101 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse

HDU 2665 &amp;&amp; POJ 2104(主席树)

http://poj.org/problem?id=2104 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <string> 5 #include <cmath> 6 #include <iostream> 7 #include <stack> 8 using namespace std; 9 #define N 100

[HDU 2665&amp;POJ 2104]K-th Number(主席树)

Description Give you a sequence and ask you the kth big number of a inteval. Solution 主席树模板题 敲完辣,心情瞬间变好,我要下楼看运动会 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #define MAXN 100005

hdu 2665 Kth number (poj 2104 K-th Number) 划分树

划分树的基本功能是,对一个给定的数组,求区间[l,r]内的第k大(小)数. 划分树的基本思想是分治,每次查询复杂度为O(log(n)),n是数组规模. 具体原理见http://baike.baidu.com/link?url=vIUKtsKYx7byeS2KCOHUI14bt_0sdHAa9BA1VceHdGsTv5jVq36SfZgBKdaHYUGqIGvIGrE_aJtqy0D0b1fCoq 个人感觉看代码是最好的学习方法. #include <cstdio> #include <c

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)