Ural 1303. Minimal Coverage
2016-08-06 11:20
991 查看
Time limit: 1.0 second |
input | output |
---|---|
1 -1 0 -5 -3 2 5 0 0 | No solution |
1 -1 0 0 1 0 0 | 1 0 1 |
Difficulty: 240 Printable
version Submit solution Discussion
(29)
My submissions All
submissions (12633) All accepted submissions (2717) Solutions
rating (1696)
给一些线段[l,r],求最少的线段能覆盖[0,m]区间
思路:
贪心,先按照起点排序,在取下一条线段时候,在不超过当前终点的条件下,能到达 的终点最远的
wa:看到有负的区间,想着要覆盖的是[0,m]的,就把负的值赋为0 ……却忘了输出要输出原线段 …………
傻了
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pi acos(-1.0) #define maxn (101000 + 50) #define mol 1000000009 #define inf 0x3f3f3f3f #define Lowbit(x) (x & (-x)) using namespace std; typedef long long int LLI; struct node { int s; int e; } op[maxn]; bool cmp(node x,node y) { if(x.s != y.s) return x.s < y.s; return x.e > y.e; } queueQue; int m,n = 0; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); scanf("%d",&m); while(~scanf("%d%d",&op .s,&op .e)) { n ++; } sort(op,op + n,cmp); int ends = 0,maxs = 0,len = 0; for(int i = 0; i < n; i ++) { if(op[i].s <= ends) { maxs = op[maxs].e > op[i].e ? maxs : i; } if(op[i].s > ends) { if(op[maxs].e < op[i].s) { ends = 0; break; } Que.push(maxs); ends = op[maxs].e; maxs = op[i].e > op[maxs].e ? i : maxs; len ++; } if(ends >= m) { maxs == -1; break; } } if(maxs != -1) { if(ends < m && op[maxs].e >= m) { ends = op[maxs].e; len ++; Que.push(maxs); } } if(ends < m) printf("No solution\n"); else { printf("%d\n",len); while(!Que.empty()) { printf("%d %d\n",op[Que.front()].s,op[Que.front()].e); Que.pop(); } } return 0; }
相关文章推荐
- ural(Timus) 1028 Stars
- Ural(Timus) 1003 Parity
- ural 1470 UFOs [树状数组]
- URAL 1806
- ural 1039
- ural 1627
- Ural 1172 Ship Routes
- URAL&nbsp;1868&nbsp;Prediction&amp;n…
- Ural 1521. War Games 2
- ural 1917. Titan Ruins: Deadly Accuracy(Titan Ruins系列)
- Ural-1009. K-based Numbers(简单组合数)
- URAL 1136 Parliament 二叉树水题 BST后序遍历建树
- URAL1021:简单问题的巧妙解答
- URAL 1181 Cutting a Painted Polygon【递归+分治】
- Ural 1087. The Time to Take Stones 递推+博弈
- Ural 1158. Censored! AC自动机+大数
- ural 1685. Orthography (树的遍历)
- URAL 1062 - Triathlon(半平面交)
- Ural 1037. Memory Management
- URAL 1069 Prufer Code 优先队列