Codeforces gym 101350F 想法
来源:互联网 发布:excel找重复数据 编辑:程序博客网 时间:2024/05/09 08:17
When the monkey professor leaves his class for a short time, all the monkeys go bananas. N monkeys are lined up sitting side by side on their chairs. They each have the same joke book. Before the professor returns, M jokes were heard.
Each of the M jokes are said in the order given and have the following properties:
xi - position of the monkey who said it.
li – index of the joke in the book.
ki – volume the monkey says that joke.
When the monkey at position xi says the joke li, all monkeys at a distance less than or equal to ki from that monkey (including the monkey who said the joke) will fall off their chairs in laughter if they have never heard the joke li before.
If the joke li has been heard anytime during the past before, and the monkey hears it again, then he will sit back up in his chair.
A monkey can fall off his chair more than once (every time he hears a new joke), and if he is already on the ground and hears a new joke, he will stay on the ground.
Can you figure out how many monkeys will be in their seats by the time the professor comes back?
The first line of input is T – the number of test cases.
The first line of each test case is N, M (1 ≤ N ≤ 105) (1 ≤ M ≤ 105) – the number of monkeys in the class, and the number of jokes said before the professor returns.
The next M lines contain the description of each joke: xi, li, ki (1 ≤ xi ≤ N) (1 ≤ li ≤ 105) (0 ≤ ki ≤ N).
For each test case, output on a line a single integer - the number of monkeys in their seats after all jokes have been said.
110 73 11 03 11 25 12 18 13 27 11 210 12 19 12 0
3
题意:有n只猴子 m个笑话
每个笑话的讲的猴子的编号 笑话的编号 传播半径
如果笑话传播到当前猴子 如果他听过 就会笑到地上 否则他会上树
问最后有几只猴子在树上
题解:先处理出所有线段 然后对于当前的猴子 找出影响他的笑话最后一个是哪个 并找出他听过这个笑话的次数
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<set>using namespace std;int num[100005],cnt;struct node{int x,y,nu,lab;}e[100005];vector<int>sp[100005];struct nodes{int num,lab;bool operator <(const nodes& a)const{if(lab==a.lab)return num<a.num;return lab<a.lab;}};set<nodes>sd;set<nodes>::iterator it;int main(){int t;scanf("%d",&t);while(t--){int n,m,i,j,x,y,z;scanf("%d%d",&n,&m);memset(num,0,sizeof(num));sd.clear();for(i=1;i<=n;i++)sp[i].clear();for(i=1;i<=m;i++){scanf("%d%d%d",&x,&y,&z);e[i].lab=i;e[i].nu=y;e[i].x=max(1,x-z);e[i].y=min(n,x+z);sp[e[i].x].push_back(i);sp[e[i].y+1].push_back(-i);}int ans=0;for(i=1;i<=n;i++){for(j=0;j<sp[i].size();j++){if(sp[i][j]>0){num[e[sp[i][j]].nu]++;sd.insert((nodes){e[sp[i][j]].nu,e[sp[i][j]].lab});}else{num[e[-sp[i][j]].nu]--;sd.erase((nodes){e[-sp[i][j]].nu,e[-sp[i][j]].lab});}}if(sd.empty())ans++;else{it=sd.end();it--;if(num[(*it).num]!=1)ans++;}}printf("%d\n",ans);}return 0;}
- Codeforces gym 101350F 想法
- codeforces Gym 101102F
- Codeforces-GYM-100726F
- Codeforces GYM 100803F
- [Gym-101350F] F
- Codeforces gym 101149 G 想法
- Codeforces gym 101149 K 想法
- Codeforces gym 101102 K 想法
- 【Codeforces Gym 100187F 】+ 贪心
- codeforces-gym-100187-F【贪心】
- Codeforces Gym 101142 F. Folding
- Codeforces Gym 101164 F. Letter
- codeforces gym 100342F Move to Front
- codeforces gym 101142 F(思维)
- Codeforces Gym 100642 C D F
- Codeforces Gym-101116-F (Flight Plan)
- Codeforces Gym 100623F Problem F. Fenwick Tree
- Codeforces Gym 100203D Different vectors 想法题 + Hash
- puts函数的使用
- php计划任务(定时执行函数)
- swustoj搭帐篷说..(0330)
- 15个顶级多线程面试题及答案
- bzoj1433: [ZJOI2009]假期的宿舍
- Codeforces gym 101350F 想法
- C语言学习历程——Training02位运算02
- UVA 7503
- jdbc
- gcd变形
- 机器学习笔记(2)-决策树
- POJ 1611 The Suspects(并查集)
- ZooKeeper集群搭建
- mysql查询练习