• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






Siriuslzx

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2012年7月14日

spoj - 7259 LITE
摘要: 涉及到lazy思想的线段树,难度大一些,不过幸好只有一种操作,扛得下。 1 #include <stdio.h> 2 #include <string.h> 3 #define N 100005 4 int tree[4*N],D; 5 bool rev[4*N]; 6 void build(int cur,int x,int y) 7 { 8 int mid=(x+y)>>1,lc=cur<<1,rc=lc|1; 9 rev[cur] = 0;10 tree[cur] = 0;11 if(x == y)12 return ;13 bui... 阅读全文
posted @ 2012-07-14 00:19 Siriuslzx 阅读(202) 评论(0) 推荐(0)
 
poj - 2352 Stars
摘要: 典型线段树,因为Input已经按Y坐标处理过了,所以程序只需处理X值就行了,也就是查询、更新。 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 const int N = 32005; 5 int tree[4*N],D; 6 int level[15010]; 7 void update(int n) 8 { 9 for(; n^1; n>>=1)10 tree[n>>1] = tree[n] + tree[n^1];11 }12 void query(in 阅读全文
posted @ 2012-07-14 00:15 Siriuslzx 阅读(142) 评论(0) 推荐(0)
 
poj - 2182 Lost Cows
摘要: 这题的意思是有编号1~N的牛,给出每个(除了第一个)牛前面比它号小的牛的个数,输出牛是怎么排的队。没想出怎么用线段树做,就当模拟题做了。 1 #include <stdio.h> 2 #include <string.h> 3 int a[8500],ans[8500]; 4 bool vis[8500]; 5 int main() 6 { 7 int n,i,j,cnt; 8 while(~scanf("%d",&n)) 9 {10 memset(vis,0,sizeof(bool)*n);11 for(i = 1; i < n; i 阅读全文
posted @ 2012-07-14 00:13 Siriuslzx 阅读(209) 评论(0) 推荐(0)
 
poj - 3264 Balanced Lineup
摘要: 简单题,求一定范围内的最大数于最小数之差,用两个数组保存max和min就行了。 1 #include <stdio.h> 2 #include <string.h> 3 #define N 50005 4 #define INF 0x7fffffff 5 int max[4*N],min[4*N]; 6 int D; 7 int Max(int a,int b) 8 { 9 return a>b ?a :b;10 }11 int Min(int a,int b)12 {13 return a<b ?a :b;14 }15 int query(int a,in 阅读全文
posted @ 2012-07-14 00:09 Siriuslzx 阅读(139) 评论(0) 推荐(0)
 
hdu 4006 The kth great number
摘要: 这题虽然是线段树的作业,但我是用pq偷懒过的,它的思路和poj 1442差不多,但要简单。 1 #include <stdio.h> 2 #include <queue> 3 using namespace std; 4 int main() 5 { 6 int m,n,k,t,cnt; 7 char ch; 8 while(~scanf("%d%d",&m,&n)) 9 {10 cnt = 0;11 priority_queue <int> small;12 priority_queue <int, vector. 阅读全文
posted @ 2012-07-14 00:06 Siriuslzx 阅读(133) 评论(0) 推荐(0)
 
hdu 1394 Minimum Inversion Number
摘要: 求最少逆序是多少,推荐用线段树,但暴力也能过,我用的方法两者皆非。我只是用暴力求第一种排列的逆序数,剩下的用小技巧推出。 1 #include <iostream> 2 using namespace std; 3 int a[5010]; 4 int main() 5 { 6 int n,i,j,ans,min; 7 while(cin>>n) 8 { 9 for(i = 0; i < n; i++)10 cin>>a[i];11 ans = 0;12 for(i = 0; i < n-1; i+... 阅读全文
posted @ 2012-07-14 00:03 Siriuslzx 阅读(157) 评论(0) 推荐(0)