URAL 1491. Unreal Story(区间染色, 数学啊)
来源:互联网 发布:网络爬虫教程 编辑:程序博客网 时间:2024/04/29 20:34
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1491
You won't believe it, but once, in ancient times, there happened the following story. At a meeting of the Round Table, King Arthur stood up and said: “Let each knight sitting on my right not farther than b places and not nearer than a places receive from me c gold coins.” If we number the knights from 1 to N counter-clockwise so that the knight sitting on Arthur's right is numbered 1 and the knight sitting on Arthur's left is numbered N, then we have that the king gave c gold coins to the knights with numbers a, a + 1, …, b.
Having looked at Arthur's generous deed, the noble knights started to stand up one after another and tell their three numbers ai, bi, ci (1 ≤ i ≤ N). After each of these utterances, the knights with numbers from ai to bi received ci gold coins each from the king.
Since each knight was very noble, either ai > i or bi < i. You task is to help the knights to learn how many gold coins each of them received.
Input
The first line contains the number of King Arthur's knights N (2 ≤ N ≤ 100000). In the next line, there are integers a, b, and c, which the king said (1 ≤ a ≤ b ≤ N; 1 ≤ c ≤ 10000). Each of the next N lines contains three integers ai, bi, ci, which the ith knight said (1 ≤ ai ≤ bi ≤ N; 1 ≤ ci ≤ 10000).
Output
Output N numbers separated with a space. The ith number is the number of gold coins received by theith knight.
Samples
42 3 22 4 13 4 11 2 11 1 1
2 4 4 2
71 7 12 3 43 5 31 2 15 7 42 4 103 4 21 6 3
5 19 23 19 11 8 5
Problem Author: Alexander Toropov
Problem Source: XIII-th USU Junior Contest, October 2006
Problem Source: XIII-th USU Junior Contest, October 2006
题意:
给出染色区间,求每个区间被染色次数!
代码如下:
#include <cstdio>#include <cstring>#include <cmath>int main(){ int n; int aa, bb, cc; int a, b, c; int s[100017]; while(~scanf("%d",&n)) { memset(s,0,sizeof(s)); scanf("%d%d%d",&aa,&bb,&cc); s[aa]+=cc, s[bb+1]-=cc; for(int i = 0; i < n; i++) { scanf("%d%d%d",&a,&b,&c); s[a]+=c, s[b+1]-=c; } int ans = 0; ans+=s[1]; printf("%d",ans); for(int i = 2; i <= n; i++) { ans+=s[i]; printf(" %d",ans); } printf("\n"); } return 0;}
1 0
- URAL 1491. Unreal Story(区间染色, 数学啊)
- ural 1019 Line Painting 线段树 区间染色
- URAL 1515. Cashmaster (数学啊 )
- URAL 1885. Passenger Comfort(数学啊 )
- URAL 1889. Airport Announcements(数学啊 )
- URAL 1718 . Rejudge(数学啊 )
- URAL 1711. Code Names (数学啊 )
- URAL 1984. Dummy Guy(数学啊)
- URAL 1725. Sold Out!(数学啊 )
- URAL 1731. Dill(数学啊 )
- URAL 1823. Ideal Gas(数学啊 )
- URAL 1617. Flat Spots(数学啊 )
- URAL 1551. Sumo Tournament(数学啊 )
- URAL 1157. Young Tiler (数学啊 )
- URAL 1510. Order(map 数学啊)
- URAL 1113(数学)
- URAL 1820. Ural Steaks(数学啊 )
- poj 2777 线段树(区间染色)
- Sql Sever修改字段属性总结(初学)
- Excel自动化公式
- [2015.2.7] 太把伤害当回事的人 都活得不太好
- 结合Robotium和Monitor类来监控活动的创建
- Plan for Perl Web Development
- URAL 1491. Unreal Story(区间染色, 数学啊)
- 第21天: 详解Select语法操作
- 导出导出直接在DOS下运行。
- CentOS 7 安装配置OpenVPN Server
- c语言的经典错误2
- AFNetworking
- LinearLayout 和 RelativeLayout
- 小鑫爱数学
- Select & Epoll