B. Train Seats Reservation

You are given a list of train stations, say from the station 1 to the station 100.

The passengers can order several tickets from one station to another before the train leaves the station one. We will issue one train from the station 1 to the station 100 after all reservations have been made. Write a program to determine the minimum number of seats required for all passengers so that all reservations are satisfied without any conflict.

Note that one single seat can be used by several passengers as long as there are no conflicts between them. For example, a passenger from station 1 to station 10 can share a seat with another passenger from station 30 to 60.

Input Format

Several sets of ticket reservations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of orders, nnn, which can be as large as 1000. After nnn, there will be nnn lines representing the nnn reservations; each line contains three integers s,t,ks, t, ks,t,k, which means that the reservation needs kkk seats from the station sss to the station ttt .These ticket reservations occur repetitively in the input as the pattern described above. An integer n=0n = 0n=0 (zero) signifies the end of input.

Output Format

For each set of ticket reservations appeared in the input, calculate the minimum number of seats required so that all reservations are satisfied without conflicts. Output a single star '*' to signify the end of outputs.

样例输入

2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0

样例输出

20
60
*

简单模拟

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/sTACK:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos[j](-1.0)
#define ei exp(1)
#define PI 3.1415926535
#define ios() ios[j]::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll a[],n,s,t,w;
int main()
{
while(scanf("%lld",&n))
{
if(n==) break;
memset(a,,sizeof(a));
for(ll i=;i<n;i++)
{
scanf("%lld%lld%lld",&s,&t,&w);
for(ll j=s;j<t;j++)
{
a[j]+=w;
}
}
ll ans=;
for(ll i=;i<=;i++)
{
ans=max(ans,a[i]);
}
printf("%lld\n",ans);
}
printf("*\n");
return ;
}

F. Overlapping Rectangles

There are nnn rectangles on the plane. The problem is to find the area of the union of these rectangles. Note that these rectangles might overlap with each other, and the overlapped areas of these rectangles shall not be counted more than once. For example, given a rectangle AAA with the bottom left corner located at (0,0) and the top right corner at (2,2), and the other rectangle BBB with the bottom left corner located at (1,1) and the top right corner at (3,3), it follows that the area of the union of A and B should be7 , instead of 8.

Although the problem looks simple at the first glance, it might take a while to figure out how to do it correctly. Note that the shape of the union can be very complicated, and the intersected areas can be overlapped by more than two rectangles.

Note:

(1) The coordinates of these rectangles are given in integers. So you do not have to worry about the floating point round-off errors. However, these integers can be as large as 1,000,000.

(2) To make the problem easier, you do not have to worry about the sum of the areas exceeding the long integer precision. That is, you can assume that the total area does not result in integer overflow.

Input Format

Several sets of rectangles configurations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of rectangles, n, which can be as large as 1000. After n, there will be n lines representing the n rectangles; each line contains four integers <a,b,c,d> , which means that the bottom left corner of the rectangle is located at (a,b), and the top right corner of the rectangle is located at (c,d). Note that integers a, b, c, d can be as large as 1,000,000.

These configurations of rectangles occur repetitively in the input as the pattern described above. An integer n=0n = 0n=0 (zero) signifies the end of input.

Output Format

For each set of the rectangles configurations appeared in the input, calculate the total area of the union of the rectangles. Again, these rectangles might overlap each other, and the intersecting areas of these rectangles can only be counted once. Output a single star '*' to signify the end of outputs.

样例输入

2
0 0 2 2
1 1 3 3
3
0 0 1 1
2 2 3 3
4 4 5 5
0

样例输出

7
3
* 求多矩形面积,可能存在重合 扫描线
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/sTACK:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos[j](-1.0)
#define ei exp(1)
#define PI 3.1415926535
#define ios() ios[j]::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = ;
int n;
struct Seg
{
double l,r,h;
int d;
Seg(){}
Seg(double l,double r,double h,int d):l(l),r(r),h(h),d(d){}
bool operator<(const Seg& rhs) const {return h<rhs.h;}
}a[N];
int cnt[N<<];
double sum[N<<],all[N];
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
void push_up(int l,int r,int rt)
{
if(cnt[rt]) sum[rt]=all[r+]-all[l];
else if(l==r) sum[rt]=;
else sum[rt]=sum[rt<<]+sum[rt<<|];
} void update(int L,int R,int v,int l,int r,int rt)
{
if(L<=l && r<=R) {
cnt[rt]+=v;
push_up(l,r,rt);
return;
}
int m = l + r >> ;
if(L<=m) update(L,R,v,lson);
if(R>m) update(L,R,v,rson);
push_up(l,r,rt);
}
int main()
{
ios_base::sync_with_stdio();
int kase = ;
while(scanf("%d",&n))
{
if(n==) break;
for(int i=;i<=n;++i)
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
a[i]=Seg(x1,x2,y1,);
a[i+n]=Seg(x1,x2,y2,-);
all[i]=x1;all[i+n]=x2;
}
n<<=;
sort(a+, a++n);
sort(all + , all++n);
int m=unique(all+,all++n)-all-;
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
double ans=;
for(int i=;i<n;++i)
{
int l=lower_bound(all+, all++m, a[i].l)-all;
int r=lower_bound(all+, all++m, a[i].r)-all;
if(l<r) update(l,r-,a[i].d,,m,);
ans+=sum[]*(a[i+].h-a[i].h);
}
printf("%.lf\n",ans);
}
printf("*\n");
return ;
}

L. The Heaviest Non-decreasing Subsequence Problem

Let S be a sequence of integers s1s_{1}s​1​​, s2s_{2}s​2​​, ........., sns_{n}s​n​​ Each integer is is associated with a weight by the following rules:

(1) If is is negative, then its weight is 0.

(2) If is is greater than or equal to 10000, then its weight is 5. Furthermore, the real integer value of sis_{i}s​i​​ is si−10000s_{i}-10000s​i​​−10000 . For example, if sis_{i}s​i​​ is 101011010110101, then is is reset to 101101101 and its weight is 555.

(3) Otherwise, its weight is 1.

A non-decreasing subsequence of SSS is a subsequence si1s_{i1}s​i1​​, si2s_{i2}s​i2​​, ........., siks_{ik}s​ik​​, with i1<i2 ... <iki_{1}<i_{2}\ ...\ <i_{k}i​1​​<i​2​​ ... <i​k​​, such that, for all 1≤j<k1 \leq j<k1≤j<k, we have sij<sij+1s_{ij}<s_{ij+1}s​ij​​<s​ij+1​​.

A heaviest non-decreasing subsequence of SSS is a non-decreasing subsequence with the maximum sum of weights.

Write a program that reads a sequence of integers, and outputs the weight of its

heaviest non-decreasing subsequence. For example, given the following sequence:

80 75 73 93 73 73 10101 97 −1 −1 114 −1 10113 118

The heaviest non-decreasing subsequence of the sequence is <73, 73, 73, 101, 113, 118> with the total weight being 1+1+1+5+5+1=14. Therefore, your program should output 141414 in this example.

We guarantee that the length of the sequence does not exceed 2∗1052*10^{5}2∗10​5​​

Input Format

A list of integers separated by blanks:s1s_{1}s​1​​, s2s_{2}s​2​​,.........,sns_{n}s​n​​

Output Format

A positive integer that is the weight of the heaviest non-decreasing subsequence.

样例输入

80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118

样例输出

14
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/sTACK:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos[j](-1.0)
#define ei exp(1)
#define PI 3.1415926535
#define ios() ios[j]::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int dp[],a[],x;
int main()
{
int n=;
while(scanf("%d",&x)!=EOF)
{
if(x>=)
{
for(int i=;i<;i++)
a[++n]=x-;
}
else if(x>=) a[++n]=x;
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
dp[upper_bound(dp,dp+,a[i])-dp]=a[i];
printf("%d\n",lower_bound(dp,dp+,INF)-dp);
return ;
}

M. Frequent Subsets Problem

Output Format

The number of α\alphaα-frequent subsets.

样例输入

15 0.4
1 8 14 4 13 2
3 7 11 6
10 8 4 2
9 3 12 7 15 2
8 3 2 4 5

样例输出

11

暴力枚举子集

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/sTACK:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos[j](-1.0)
#define ei exp(1)
#define PI 3.1415926535
#define ios() ios[j]::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,val[],x,k;
double f;
char ch;
int main()
{
scanf("%d%lf",&n,&f);
k=;
while(~scanf("%d%c",&x,&ch))
{
val[k]+=(<<(x-));
if(ch=='\n') k++;
}
int ans=,cnt;
int pos=ceil(f*k);
for(int i=;i<(<<n);i++)
{
cnt=;
for(int j=;j<k;j++)
{
if((i&val[j])==i) printf("%d %d\n",i,val[j]),cnt++;
}
ans+=cnt>=pos?:;
}
printf("%d\n",ans);
return ;
}

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 (B,F,L,M)的更多相关文章

  1. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】

    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛  M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...

  2. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  3. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  4. ICPC 2018 徐州赛区网络赛

    ACM-ICPC 2018 徐州赛区网络赛  去年博客记录过这场比赛经历:该死的水题  一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进.     D. Easy Math 题意:   ...

  5. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)

    参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...

  6. [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题

    第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...

  7. 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit    1000 ms Memory li ...

  8. 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!

    鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Fo ...

  9. 2017ICPC南宁赛区网络赛 Minimum Distance in a Star Graph (bfs)

    In this problem, we will define a graph called star graph, and the question is to find the minimum d ...

随机推荐

  1. MATLAB曲线拟合

    转自原文 MATLAB曲线拟合 曲线拟合 实例:温度曲线问题 气象部门观测到一天某些时刻的温度变化数据为: t 0 1 2 3 4 5 6 7 8 9 10 T 13 15 17 14 16 19 2 ...

  2. 待字闺中之Magic Index 分析

    给定一个数组A,当中有一个位置被称为Magic Index,含义是:如果i是Magic Index.则A[i] = i. 如果A中的元素递增有序.且不反复,请给出方法,找到这个Magic Index. ...

  3. 很好的DP思路,字符串比较次数

    题目: https://leetcode.com/problems/distinct-subsequences/?tab=Description 一般没有明显思路的情况下,都要想想DP,用下Divid ...

  4. 3、Python字典集合

    2.3字典 字典是键值对的无序可变序列.键值之间用冒号隔开,相邻元素之间用逗号隔开,所有元素放在大括号之间{},键可以是Python中所有不可变的数据,不能用列表.元组.字典作为字典的键,键不可重复, ...

  5. 聊聊高并发(四十四)解析java.util.concurrent各个组件(二十) Executors工厂类

    Executor框架为了更方便使用,提供了Executors这个工厂类.通过一系列的静态工厂方法.能够高速地创建对应的Executor实例. 仅仅有一个nThreads參数的newFixedThrea ...

  6. zzulioj--1828-- 贪心的小猫咪(贪心模拟)

    1828: 贪心的小猫咪 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 14  Solved: 4 SubmitStatusWeb Board Des ...

  7. Linux环境下源码安装PostgreSQL

    1.下载PostgreSQL源码包,并保存到Linux操作系统的一个目录下 2.解压PostgreSQL源码包 :tar zxvf postgresql-9.2.4.tar.gz 或 tar jxvf ...

  8. vue子组件使用指令 同时绑定v-model 指令没有作用

    //这里直接上代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  9. css hover图片hover效果兼容ie8

    例子: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  10. hadoop的mapReduce和Spark的shuffle过程的详解与对比及优化

    https://blog.csdn.net/u010697988/article/details/70173104 大数据的分布式计算框架目前使用的最多的就是hadoop的mapReduce和Spar ...