题意:给定 n 个区间,让你进行合并,问你最后的区间是,如果是空集,输出 false 如果区间是是 [-32768,32767] ,则是true。

析:进行区间合并,要注意,如果是 x >= 0 && x <= 32767 那么输出是  x >= 0,在这地方,真是错死了。。。。。。后来看了数据才知道有这个,其他的就是进行区间合并,如果第 i 个和第 j 个区间合并时,假设 x >= a && x <= b  || x >= c && x <= d,那么如果 b+1 >= c && a <= c || d+1 >= a && c <= a  就进行合并,当然对于单向的就进行一个标记左端点是-32768右端点是32767,也就是最后在输出。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e15;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 500;
const LL mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} struct Node{
int small, big;
bool flag;
}; Node a[maxn]; int clac(const string &s){
int ans = 0;
int sig = s[0] == '-' ? -1 : 1;
ans = s[0] == '-' ? 0 : s[0] - '0';
for(int i = 1; i < s.sz; ++i)
ans = ans * 10 + s[i] - '0';
return ans * sig;
} vector<Node> ans; int main(){
freopen("hard.in", "r", stdin);
freopen("hard.out", "w", stdout);
string s;
int idx = 0;
while(getline(cin, s)){
a[idx].flag = 0;
if(s[2] == '>'){
stringstream ss(s);
string t;
ss >> t; ss >> t;
ss >> t;
a[idx].big = clac(t);
if((ss >> t)) {
if(t == "||") a[idx].small = 32767;
else{
ss >> t >> t;
ss >> t;
a[idx].small = clac(t);
}
}
else a[idx].small = 32767;
}
else{
stringstream ss(s);
string t;
ss >> t; ss >> t;
ss >> t;
a[idx].small = clac(t);
a[idx].big = -32768;
}
if(a[idx].big < -32768 || a[idx].small > 32767) a[idx].flag = 1;
++idx;
} bool ok = false;
for(int i = 0; i < idx; ++i){
if(a[i].small >= a[i].big){
ok = true;
}
} if(!ok){ puts("false"); return 0; } for(int k = 0; k < 10; ++k)
for(int i = 0; i < idx; ++i){
if(a[i].small < a[i].big) a[i].flag = 1;
if(a[i].flag) continue;
for(int j = 0; j < idx; ++j){
if(a[j].small < a[j].big) a[j].flag = 1;
if(i == j) continue;
if(a[j].flag) continue;
if(a[i].big <= a[j].small+1 && a[i].small >= a[j].small || a[j].big <= a[i].small+1 && a[i].small <= a[j].small){
a[i].small = max(a[i].small, a[j].small);
a[i].big = min(a[i].big, a[j].big);
a[j].flag = 1;
}
}
} for(int i = 0; i < idx; ++i)
if(!a[i].flag) ans.pb(a[i]); if(ans[0].small == 32767 && ans[0].big == -32768) puts("true");
else {
for(int i = 0; i < ans.sz; ++i){
if(ans[i].big > -32768){
printf("x >= %d", ans[i].big);
if(ans[i].small < 32767) printf(" && x <= %d", ans[i].small);
}
else printf("x <= %d", ans[i].small);
if(i != ans.sz-1) printf(" ||");
puts("");
}
} return 0;
}

  

Gym 101190H Hard Refactoring (模拟坑题)的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)

    1952: [Sdoi2010]城市规划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 23[Submit][Status][ ...

  3. hdu 5455 Fang Fang 坑题

    Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 ...

  4. String类面试坑题

    1.面试坑题F:\SHJT\JavaWorkspace\JavaSE\workspace\day13ezra\src\cn\itcast\sh\classcode\BTStringLastIndexO ...

  5. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  6. Codeforces Gym 100650C The Game of Efil 模拟+阅读题

    原题链接:http://codeforces.com/gym/100650/attachments/download/3269/20052006-acmicpc-east-central-north- ...

  7. Gym 100851E Easy Problemset (模拟题)

    Problem E. Easy ProblemsetInput file: easy.in Output file: easy.outPerhaps one of the hardest problems ...

  8. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  9. hdu 5083 有坑+字符串模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5083 机器码和操作互相转化 注意SET还要判断末5位不为0输出Error #pragma comment(lin ...

随机推荐

  1. 安装git之后,桌面图标出现很多的蓝色问号

    今天在搞git之后,开机发现多了好多的问号: 这是因为我们在桌面创建了版本库了. 这个时候我们在系统中吧隐藏的文件夹显示出来.这个时候会看到桌面上有一个隐藏的git文件夹.把这个文件夹删除掉之后,刷新 ...

  2. 【HDU】2222 Keywords Search(AC自动机)

    题目 传送门:QWQ 分析 $ AC $自动机模板,黈力的码风真的棒极了,这是我抄他的. 还有 题号不错 代码 #include <cstdio> #include <cstring ...

  3. java集合遍历删除指定元素异常分析总结

    在使用集合的过程中,我们经常会有遍历集合元素,删除指定的元素的需求,而对于这种需求我们往往使用会犯些小错误,导致程序抛异常或者与预期结果不对,本人很早之前就遇到过这个坑,当时没注意总结,结果前段时间又 ...

  4. Tkinter tkMessageBox

            Tkinter tkMessageBox: tkMessageBox模块用于显示在您的应用程序的消息框.此模块提供了一个功能,您可以用它来显示适当的消息  tkMessageBox模块 ...

  5. day9-数据库操作与Paramiko模块

    堡垒机前戏 开发堡垒机之前,先来学习Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: 1 ...

  6. [转] 基于C#的波形显示控件的实现

    转自 基于C#的波形显示控件的实现[附完整源码下载] 编者记: 09年暑假正好在学院实验室呆了一段时间,做了个完整的上位机软件(具体实现:根据下位机的指令,实现通过串口来操纵下位机进行实验,并将采集的 ...

  7. 「小程序JAVA实战」小程序视图之条件判断(15)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-15/ 小程序里面也是有条件判断的,我相信大家在开发java if和jstl c:if c:when ...

  8. java 控制台 输入字符串

    import java.util.Scanner; //导入输入类 public static void main(String[] args) {      //创建输入对象   Scanner s ...

  9. ffmpeg基本用法(转)

    FFmpeg FFmpeg 基本用法 本课要解决的问题 1.FFmpeg的转码流程是什么? 2.常见的视频格式包含哪些内容吗? 3.如何把这些内容从视频文件中抽取出来? 4.如何从一种格式转换为另一种 ...

  10. python中heapq堆的讲解

    堆的定义: 堆是一种特殊的数据结构,它的通常的表示是它的根结点的值最大或者是最小. python中heapq的使用 列出一些常见的用法: heap = []#建立一个常见的堆 heappush(hea ...