bzoj1664
来源:互联网 发布:ftp同步数据库备份 编辑:程序博客网 时间:2024/05/18 17:24
标程 :
树状数组优化
#include<bits/stdc++.h>using namespace std;#define FOR(i,s,t) for(int i=(s);i<=(t);i++)inline int read(void){ int x = 0, c, f = 1; do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9'); do{x=x*10+c-'0';c=getchar();}while(c>='0'&&c<='9'); return x * f;}const int N = 11000;struct node{ int x, y; bool operator < (const node &t) const { return x != t.x ? x < t.x : y < t.y; }} e[N];int n, f[N];#define lb(x) (x&-x)const int M = 100000;int cnt[M + 10];inline void Updata(int pos, int x) { for (int i = pos; i <= M; i += lb(i)) cnt[i] = max(cnt[i], x);}inline int Query(int pos) { int ret = 0; for (int i = pos; i; i ^= lb(i)) { ret = max(ret, cnt[i]); } return ret;}int main(){ n = read(); for (int i = 1; i <= n; i++) { e[i].x = read(), e[i].y = e[i].x + read() - 1; } sort(e+1,e+n+1); int ans = 0; for (int i = 1; i <= n; i++) { f[i] = Query(e[i].x - 1); ans = max(ans, ++f[i]); Updata(e[i].y, f[i]); } cout << ans << endl;}
数据范围出小了, 所以暴力踩标程:
#include<bits/stdc++.h>using namespace std;#define FOR(i,s,t) for(int i=(s);i<=(t);i++)inline int read(void){ int x = 0, c, f = 1; do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9'); do{x=x*10+c-'0';c=getchar();}while(c>='0'&&c<='9'); return x * f;}const int N = 11000;struct node{ int x, y; bool operator < (const node &t) const { return x != t.x ? x < t.x : y < t.y; }} e[N];int n, f[N];int main(){ n = read(); for (int i = 1; i <= n; i++) { e[i].x = read(), e[i].y = e[i].x + read() - 1; } sort(e+1,e+n+1); int ans = 0; for (int i = 1; i <= n; i++) { for (int j = i - 1; j; j--) if (e[i].x > e[j].y) f[i] = max(f[i], f[j]); ans = max(ans, ++f[i]); } cout << ans << endl;}
阅读全文
0 0
- bzoj1664
- bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
- [BZOJ1664] [Usaco2006 Open]County Fair Events 参加节日庆祝
- 【BZOJ1664】[Usaco2006 Open]County Fair Events 参加节日庆祝【线段覆盖】【贪心】
- LeetCode#33. Search in Rotated Sorted Array
- 网络编程练习字符串反转
- 关于unity结构体struct和类class的使用细节和注意事项!
- 文章标题
- Python3 网络套接字(socket / socketserver)
- bzoj1664
- json数据处理
- Python 边做边学 1 需求分析
- Python 正则表达式入门(初级篇)
- C++作业6
- Keil C51重定向printf到串口
- [AHOI2009] BZOJ2431 逆序对数列-动态规划-前缀和优化
- android 分析ANR问题
- 进程通信—命名管道