CF1101C Division and Union 线段相交问题
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 100005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int T;
int n;
struct node {
int l, r;
bool operator<(const node&rhs)const {
if (l < rhs.l)return true;
if (l > rhs.l)return false;
if (l == rhs.l)return r < rhs.r;
}
}line[maxn];
int l[maxn], r[maxn]; int main() {
//ios::sync_with_stdio(0);
rdint(T);
while (T--) {
rdint(n);
for (int i = 1; i <= n; i++) {
rdint(l[i]); rdint(r[i]);
line[i].l = l[i]; line[i].r = r[i];
}
sort(line + 1, line + 1 + n);
bool fg = false;
int R = -1;
for (int i = 1; i <= n; i++) {
if (i == 1)R = line[i].r;
if (line[i].l > R) {
fg = true; break;
}
else R = max(R, line[i].r);
}
if (!fg) {
cout << -1 << endl;
}
else {
for (int i = 1; i <= n; i++) {
if (r[i] <= R) {
cout << 1 << ' ';
}
else cout << 2 << ' ';
}
cout << endl;
}
}
return 0;
}
CF1101C Division and Union 线段相交问题的更多相关文章
- poj 1127:Jack Straws(判断两线段相交 + 并查集)
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2911 Accepted: 1322 Descr ...
- POJ 1066 Treasure Hunt (线段相交)
题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...
- POJ 2653 Pick-up sticks (线段相交)
题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...
- HDU1086You can Solve a Geometry Problem too(判断线段相交)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- POJ 2653 Pick-up sticks【线段相交】
题意:n根木棍随意摆放在一个平面上,问放在最上面的木棍是哪些. 思路:线段相交,因为题目说最多有1000根在最上面.所以从后往前处理,直到木棍没了或者最上面的木棍的总数大于1000. #include ...
- POJ 1556 The Doors【最短路+线段相交】
思路:暴力判断每个点连成的线段是否被墙挡住,构建图.求最短路. 思路很简单,但是实现比较复杂,模版一定要可靠. #include<stdio.h> #include<string.h ...
- 还记得高中的向量吗?leetcode 335. Self Crossing(判断线段相交)
传统解法 题目来自 leetcode 335. Self Crossing. 题意非常简单,有一个点,一开始位于 (0, 0) 位置,然后有规律地往上,左,下,右方向移动一定的距离,判断是否会相交(s ...
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- hdu 1558 线段相交+并查集
题意:要求相交的线段都要塞进同一个集合里 sol:并查集+判断线段相交即可.n很小所以n^2就可以水过 #include <iostream> #include <cmath> ...
随机推荐
- springmvc----demo1---hello---bai
import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import ...
- ASP.NET——配置文件——连接字符串
一.连接字符串 1.通过<connectionStrings>方式: 方式一:SqlServer身份验证 <connectionStrings> <add name=&q ...
- IOS 屏幕尺寸
型号 屏幕尺寸(英寸) 分辨率(pt) 像素分辨率(px)iPhone 3G 3.5 320*480 480x320iPhone 3GS 3.5 320*480 480x320iPhone4 3. ...
- LinearLayout线性布局搭配权重属性的使用
在开发中,我们是通过布局来完成应用界面的搭配的,通过各种布局,我们可以完成各种复杂的界面设计.而LinearLayout也就是我们说的线性布局,这个比较简单而且使用很广泛的一种布局.下面我们通过一个D ...
- java判断姓是否合格 百家姓
package util; import java.lang.reflect.Array; public class FirstName { public static boolean ClearNa ...
- Python的安装以及路径的设置(python的下载地址:www.python.org)
在有的Python版本中在安装时,我们的可以再安装时选择Python路径的自动配备 在选择python的安装程序的时候,我们尽量选择python的2.版本,因为随着Python的更新,Python的数 ...
- [转]SQL 模糊查询
在进行数据库查询时,有完整查询和模糊查询之分. 一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: 1,% :表 ...
- Python 网络爬虫 004 (编程) 如何编写一个网络爬虫,来下载(或叫:爬取)一个站点里的所有网页
爬取目标站点里所有的网页 使用的系统:Windows 10 64位 Python语言版本:Python 3.5.0 V 使用的编程Python的集成开发环境:PyCharm 2016 04 一 . 首 ...
- 基于GStreamer编写Mp3播放器
一.简介 作者系统为CentOS6,本文在此基础上对Mp3播放器进行开发,需要使用mp3解码库libmad和gstreamer0.10-plugins-ugly,详细步骤如下. 二.操作步骤 1) ...
- libmad介绍
一.简介 libmad是一个开源mp3解码库,其对mp3解码算法做了很多优化,性能较好,很多播放器如mplayer.xmms等都是使用这个开源库进行解码的:如果要设计mp3播放器而又不想研究mp3解码 ...