codevs 1292 核仁巧克力

我犯了跟上次一样地错误,又以为要可持久化了。。好在马上反应了过来

同样的扫描线线段树没啥意思

还有记着最大值变化后那个记录Ollie的数组要重新初始化。。。

只是数据有个点是个track

只有一列,答案都是0;我就挂了一次,特判掉就好

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<algorithm>
  4 #include<vector>
  5 #include<ext/pb_ds/assoc_container.hpp>
  6 #define maxn 200020
  7 using namespace std;
  8 using namespace __gnu_pbds;
  9 gp_hash_table<int,int> ha;
 10 struct data{
 11     int x,y;
 12 }v[maxn];
 13 bool cmp(data a,data b){
 14     return a.x < b.x;
 15 }
 16 bool cmp2(data a,data b){
 17     return a.y < b.y;
 18 }
 19 struct node{
 20     int va;
 21     int l,r;
 22     node* left;
 23     node* right;
 24 }e[maxn*10];
 25 int tot = -1;
 26 int n;
 27 int a,b;
 28 int py[maxn];
 29 int cy[maxn];
 30 int h[maxn];
 31 int vh[maxn];
 32 vector<data> vec[maxn];
 33 int cnt1 = -1;
 34 int cnt = 0;
 35 int cnt3 = 0;
 36 inline void update(node* x){
 37     x->va = x->left->va + x->right->va;
 38 }
 39 node* build1(int l,int r){
 40     node* cur = &e[++tot];
 41     cur->l = l;
 42     cur->r = r;
 43     cur->va = 0;
 44     if(l == r){
 45         return cur;
 46     }
 47     int mid = (l+r) >>1;
 48     cur->left = build1(l,mid);
 49     cur->right = build1(mid+1,r);
 50     return cur;
 51 }
 52 void modify(node* cur,int p){
 53     if(cur->l == cur->r){
 54         cur->va++;
 55         return;
 56     }
 57     int mid = (cur->l + cur->r) >>1;
 58     if(p <= mid){
 59         modify(cur->left,p);
 60     }
 61     else{
 62         modify(cur->right,p);
 63     }
 64     update(cur);
 65 }
 66 int find(node* cur,int l,int r){
 67     if(cur->l == l && cur->r == r){
 68         return cur->va;
 69     }
 70     int mid = (cur->l + cur->r) >>1;
 71     if(r <= mid){
 72         return find(cur->left,l,r);
 73     }
 74     else if(l > mid){
 75         return find(cur->right,l,r);
 76     }
 77     else{
 78         return find(cur->left,l,mid) +find(cur->right,mid+1,r);
 79     }
 80 }
 81 node* root1;
 82 int others[maxn];
 83 int cothers[maxn];
 84 int cnt2 = -1;
 85 int main(){
 86     scanf("%d",&n);
 87     for(int i =0;i<n;i++){
 88         scanf("%d %d",&a,&b);
 89         v[i].x =a;
 90         v[i].y =b;
 91         py[i] = b;
 92     }
 93     sort(py,py+n);
 94     cy[0] = py[0];
 95     for(int i =1;i<n;i++){
 96         if(py[i] != py[i-1]){
 97             cy[++cnt] = py[i];
 98         }
 99     }
100     for(int i =0;i<=cnt;i++){
101         ha[cy[i]] = i;
102     }
103     for(int i =0;i<n;i++){
104         h[ha[v[i].y]]++;
105     }
106     vh[cnt] = h[cnt];
107     for(int i =cnt-1;i>=0;i--){
108         vh[i] = vh[i+1] + h[i];
109     }
110     root1 = build1(0,cnt);
111     sort(v,v+n,cmp);
112     vec[++cnt1].push_back(v[0]);
113     for(int i =1;i<n;i++){
114         if(v[i].x != v[i-1].x){
115             sort(vec[cnt1].begin(),vec[cnt1].end(),cmp2);
116             cnt1++;
117         }
118         vec[cnt1].push_back(v[i]);
119     }
120     if(cnt1 == 0){
121         printf("Stan: 0; Ollie: 0;\n");
122         return 0;
123     }
124     int nowy;
125     int nowyid;
126     int find1;
127     int find2;
128     int cfind2;
129     int minfind;
130     int minfindc;
131     int maxfinda = -99999999;
132     int other = 0;
133     for(int i =0;i<=cnt1;i++){
134         minfind = 99999999;
135         for(int j =0;j<vec[i].size();j++){
136             nowy = vec[i][j].y;
137             nowyid = ha[nowy];
138             find1 = 0;
139             if(nowyid != 0){
140                 find1 = find(root1,0,nowyid-1);
141             }
142             cfind2 = find2 = 0;
143             if(nowyid != cnt){
144                 find2 = find(root1,nowyid+1,cnt);
145                 cfind2 = vh[nowyid+1] - find2 - (vec[i].size()-j-1);
146             }
147             if(find1 + cfind2 < minfind){
148                 minfind = find1+cfind2;
149                 minfindc = h[nowyid]+vec[i].size()-1;
150             }
151         }
152         if(maxfinda < minfind){
153             maxfinda = minfind;
154             other = n - maxfinda - minfindc;
155             cnt2 = -1;
156             others[++cnt2] = other;
157         }
158         else if(maxfinda == minfind){
159             other = n - maxfinda - minfindc;
160             others[++cnt2] = other;
161         }
162         for(int j = 0;j<vec[i].size();j++){
163             int check = ha[vec[i][j].y];
164             modify(root1,check);
165         }
166     }
167     printf("Stan: %d; ",maxfinda);
168     sort(others,others+cnt2+1);
169     cothers[0] = others[0];
170     for(int i =1;i<=cnt2;i++){
171         if(others[i] != others[i-1]){
172             cothers[++cnt3] = others[i];
173         }
174     }
175     printf("Ollie: ");
176     for(int i =0;i<=cnt3-1;i++){
177         printf("%d ",cothers[i]);
178     }
179     printf("%d;",cothers[cnt3]);
180     return 0;
181 } 
时间: 2024-08-01 22:45:36

codevs 1292 核仁巧克力的相关文章

[ CodeVS冲杯之路 ] P2492

不充钱,你怎么AC? 题目:http://codevs.cn/problem/2492/ 在此先orz小胖子,教我怎么路径压缩链表,那么这样就可以在任意节点跳进链表啦(手动@LCF) 对于查询操作,直接树状数组(以下简称BIT)维护,修改操作就一个个暴力开方搞,再用差值单点更新BIT 不过这样会TLE,要加一点优化对不对,正如开头所说的路径压缩链表 路径压缩链表其实就是个并查集,在普通的链表里,删去两个连续的节点后会是下面这种情况,如删去2,3 当访问 2 的时候,会跳到3,但 3 已经删除了,

[CODEVS 1281] Xn数列

描述 给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn http://codevs.cn/problem/1281/ 分析 比较裸的矩阵乘法题, 好久没做了, 写写思路 假设矩阵 A = { {a1, a2}, {a3, a4} }, B = { {b1, b2}, {b3, b4} }. 根据矩阵乘法的计算方法, 有 : A×B = { {a1b1+a2b2, a1b2+a2b4}, {a3b1+a4b3, a3b2+a4b4} }. 那

T7314 yyy的巧克力(钟)

题目描述 输入输出格式 输入格式: 如图 输出格式: 如图 输入输出样例 输入样例#1: 如图 输出样例#1: 如图 说明 如图 n*m-1 我们可以这样想,1*1的巧克力一定是由1*2的掰开的 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<queue> 7 #

P2183 巧克力(二分答案)

P2183 巧克力 题目描述 佳佳邀请了M个同学到家里玩.为了招待客人,她需要将巧克力分给她的好朋友们.她有N(1<=N<=5000)块巧克力,但是大小各不一样,第i块巧克力大小为为1*Xi(1<=i<=N,1<=Xi<=10000) 为了公平,她需要让每人所分得的巧克力大小一样,而且为了礼貌,巧克力是一整块地分给客人.所以她需要将巧克力分成大小为S的M块,而且使得S最大.但她很忙还要照顾她的客人,所以就将任务交给你了,你需要求出S. 输入输出格式 输入格式: 第一行,

Codevs 1257 打砖块

1257 打砖块 http://codevs.cn/problem/1257/ 题目描述 Description 在一个凹槽中放置了n层砖块,最上面的一层有n块砖,第二层有n-1块,……最下面一层仅有一块砖.第i层的砖块从左至右编号为1,2,……i,第i层的第j块砖有一个价值a[i,j](a[i,j]<=50).下面是一个有5层砖块的例子.如果你要敲掉第i层的第j块砖的话,若i=1,你可以直接敲掉它,若i>1,则你必须先敲掉第i-1层的第j和第j+1块砖. 你的任务是从一个有n(n<=5

codevs——T1219 骑士游历

 http://codevs.cn/problem/1219/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 设有一个n*m的棋盘(2≤n≤50,2≤m≤50),如下图,在棋盘上有一个中国象棋马. 规定: 1)马只能走日字 2)马只能向右跳 问给定起点x1,y1和终点x2,y2,求出马从x1,y1出发到x2,y2的合法路径条数. 输入描述 Input Description 第一行2个整数n和m 第二行4个

1683 车厢重组 codevs

http://codevs.cn/problem/1683/ 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题目描述 Description 在一个旧式的火车站旁边有一座桥,其桥面可以绕河中心的桥墩水平旋转.一个车站的职工发现桥的长度最多能容纳两节车厢,如果将桥旋转180度,则可以把相邻两节车厢的位置交换,用这种方法可以重新排列车厢的顺序.于是他就负责用这座桥将进站的车厢按车厢号从小到大排列.他退休后,火车站决定将这一工作自动化,其中一项重要的工作是编一个程序

codevs 1487 大批整数排序(水题日常)

时间限制: 3 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题目描述 Description !!!CodeVS开发者有话说: codevs自从换了评测机,新评测机的内存计算机制发生变化 计算内存的时候会包括栈空间 swap空间 这题的2M是单指内存空间... 十分十分抱歉 抱歉 !!! 现在有一大批(总数不超过10000000个)1到10之间的整数,现在请你从小到大进行排序输出. (测试数据将超过11MB.) 输入描述 Input Description 第一行表示将下排序

巧克力(zoj 1363)

2100年,ACM牌巧克力将风靡全球. "绿的,橘红的,棕色的,红的-",彩色的糖衣可能是ACM巧克力最吸引人的地方.你一共见过多少种颜色?现在,据说ACM公司从一个24种颜色的调色板中选择颜色来装饰他们的美味巧克力. 有一天,Sandy用一大包有五种颜色的巧克力玩了一个游戏.每次他从包里拿出一粒巧克力并把它放在桌上.如果有桌上有两粒相同颜色的巧克力,他就把他们吃掉.他惊奇的发现大多数时候桌上都有2到3粒巧克力. 如果ACM巧克力有C(1≤C≤100)种颜色,在拿出了N(1≤N≤100