lower_bound: Spider's Web (CF#133)
来源:互联网 发布:美式乡村风格知乎 编辑:程序博客网 时间:2024/06/04 23:42
Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web.
There are n main threads going from the center of the web. All main threads are located in one plane and divide it inton equal infinitesectors. The sectors are indexed from 1 to n in the clockwise direction. Sectorsi andi + 1 areadjacent for every i, 1 ≤ i < n. In addition, sectors1 andn are also adjacent.
Some sectors have bridge threads. Each bridge connects the two main threads that make up this sector. The points at which the bridge is attached to the main threads will be calledattachment points. Both attachment points of a bridge are at the same distance from the center of the web. At each attachment point exactly one bridge is attached. The bridges areadjacent if they are in the same sector, and there are no other bridges between them.
A cell of the web is a trapezoid, which is located in one of the sectors and is bounded by two main threads and two adjacent bridges. You can see that the sides of the cell may have the attachment points of bridges from adjacent sectors. If the number of attachment points on one side of the cell is not equal to the number of attachment points on the other side, it creates an imbalance of pulling forces on this cell and this may eventually destroy the entire web. We'll call such a cell unstable. The perfect web does not contain unstable cells.
Unstable cells are marked red in the figure. Stable cells are marked green.
Paw the Spider isn't a skillful webmaker yet, he is only learning to make perfect webs. Help Paw to determine the number of unstable cells in the web he has just spun.
The first line contains integer n (3 ≤ n ≤ 1000) — the number of main threads.
The i-th of following n lines describe the bridges located in the i-th sector: first it contains integer ki (1 ≤ ki ≤ 105) equal to the number of bridges in the given sector. Then follow ki different integers pij (1 ≤ pij ≤ 105; 1 ≤ j ≤ ki). Number pij equals the distance from the attachment points of thej-th bridge of thei-th sector to the center of the web.
It is guaranteed that any two bridges between adjacent sectors are attached at a different distance from the center of the web. It is guaranteed that the total number of the bridges doesn't exceed105.
Print a single integer — the number of unstable cells in Paw the Spider's web.
73 1 6 74 3 5 2 92 8 14 3 7 6 43 2 5 93 6 3 83 4 2 9
6
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <vector>using namespace std;int main(){ int n, m; vector<int> v[1010]; scanf("%d", &n); for(int i = 0; i < n; i ++){ scanf("%d", &m); while(m --){ int a; scanf("%d", &a); v[i].push_back(a); } sort(v[i].begin(), v[i].end()); } int ans = 0; for(int i = 0; i < n; i ++){ int last = (i - 1) < 0 ? (n - 1) : i - 1; int next = (i + 1) % n; for(int j = 1; j < v[i].size(); j ++){ int low = v[i][j-1]; int high = v[i][j]; int lastNum = lower_bound(v[last].begin(), v[last].end(), high) - lower_bound(v[last].begin(), v[last].end(), low); int nextNum = lower_bound(v[next].begin(), v[next].end(), high) - lower_bound(v[next].begin(), v[next].end(), low); ans += (lastNum != nextNum); } } printf("%d\n", ans); return 0;}
- lower_bound: Spider's Web (CF#133)
- CF Spider's Web 二分
- CodeForces 216D Spider's Web
- Web Spider
- Codeforces 216D Spider's Web 树状数组+模拟
- Python Spider, Web Crawler
- pre-emptive multithreading web spider
- Web Spider 网络蜘蛛爬虫
- Web Spider的一些资料
- Spider
- spider
- Spider
- spider
- spider
- spider
- Spider
- Spider
- lower_bound
- NYOJ 110 剑客决斗(DP)
- IOS上OGLES 的shader文件无法打包问题
- Linux内核开发之阻塞非阻塞IO----轮询操作
- 深入浅出FPGA-12-VMM(验证方法学)
- current_date与sysdate区别
- lower_bound: Spider's Web (CF#133)
- IOS 消息推送原理及实现总结
- opendiff and FileMerge on OS X
- 【android模拟器 avd路径错误】Could not open AVD config file: D:\鎴戠殑鏂囨。\.android\.android\avd\jjjj.avd/config.
- 上传文件检测真实类型
- python 调用smtplib输出重定向问题
- 网页特效大全
- IE浏览器内存泄露检测工具
- [博弈] hdu 4371 alice and bob