Codeforces Beta Round #10 B. Cinema Cashier (树状数组)
题目大意:
n波人去k*k的电影院看电影。
要尽量往中间坐,往前坐。
直接枚举,贪心,能坐就坐,坐在离中心近期的地方。
- #include <cstdio>
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- #define maxn 1000005
- #define lowbit(x) (x&(-x))
- using namespace std;
- struct BIT
- {
- int sum;
- void init(){sum=0;}
- }bit[105][105];
- int q,n;
- int Sum(int row,int x)
- {
- int ret=0;
- for(int i=x;i>=1;i-=lowbit(i))
- ret+=bit[row][i].sum;
- return ret;
- }
- int query(int row,int l,int r)
- {
- return Sum(row,r)-Sum(row,l-1);
- }
- void update(int row,int x)
- {
- for(int i=x;i<=n;i+=lowbit(i))
- bit[row][i].sum++;
- }
- int cal(int s,int e)
- {
- return (s+e)*(e-s+1)/2;
- }
- int main()
- {
- scanf("%d%d",&q,&n);
- int cen=n/2+1;
- for(int i=0;i<=n;i++)
- for(int j=0;j<=n;j++)
- {
- bit[i][j].init();
- }
- for(int i=1;i<=q;i++)
- {
- int num;
- scanf("%d",&num);
- int ansr=-1,ansc=-1;
- int min_val=0x3f3f3f3f;
- for(int r=1;r<=n;r++)
- {
- for(int c=1;c+num-1<=n;c++)
- {
- if(query(r,c,c+num-1)==0)
- {
- int tmp;
- if(c>=cen)
- {
- tmp=cal(c,c+num-1)-cen*num+abs(r-cen)*num;
- }
- else if(c+num-1<=cen)
- {
- tmp=cen*num-cal(c,c+num-1)+abs(r-cen)*num;
- }
- else
- {
- tmp=abs(r-cen)*num+cal(cen,c+num-1)-(c+num-cen)*cen+cen*(cen-c)-cal(c,cen-1);
- }
- if(tmp<min_val)
- {
- min_val=tmp;
- ansr=r;
- ansc=c;
- }
- }
- }
- }
- if(min_val!=0x3f3f3f3f)
- {
- printf("%d %d %d\n",ansr,ansc,ansc+num-1);
- for(int j=ansc;j<=ansc+num-1;j++)
- update(ansr,j);
- }
- else puts("-1");
- }
- return 0;
- }
Codeforces Beta Round #10 B. Cinema Cashier (树状数组)的更多相关文章
- Codeforces Beta Round #10 B. Cinema Cashier 暴力
B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...
- Educational Codeforces Round 10 D. Nested Segments (树状数组)
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...
- Codeforces Round #365 (Div. 2) D 树状数组+离线处理
D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #261 (Div. 2) D 树状数组应用
看着题意:[1,i]中等于a[i]的个数要大于[,jn]中等于a[j]的个数 且i<j,求有多少对这种(i,j) ,i<j可是 i前面的合法个数 要大于j后面的 看起来非常像逆序数的样子 ...
- Codeforces 703D Mishka and Interesting sum(树状数组+扫描线)
[题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...
- codeforces 985 E. Pencils and Boxes (dp 树状数组)
E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CodeForces 380C Sereja and Brackets(扫描线+树状数组)
[题目链接] http://codeforces.com/problemset/problem/380/C [题目大意] 给出一个括号序列,求区间内左右括号匹配的个数. [题解] 我们发现对于每个右括 ...
- CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)
树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且代码量和常数较小 首先定义一个数组 int c[N]; 并清空 memset(c, 0, sizeof c) ...
- Codeforces 390E Inna and Large Sweet Matrix 树状数组改段求段
题目链接:点击打开链接 题意:给定n*m的二维平面 w个操作 int mp[n][m] = { 0 }; 1.0 (x1,y1) (x2,y2) value for i : x1 to x2 for ...
随机推荐
- Arduino M0 的一个坑(2015-12-25)
前几天收到 Arduino M0,试各项功能都正常,可就是串口监视器/串口助手不能显示程序里打印的输出,好生奇怪,各种换波特率各种PC串口程序换着试,资料不多,官方资料也只说到 Serial1 用于 ...
- python3.4.3如何获取文件的路径
#coding:utf-8from tkinter import *from tkinter import filedialogroot = Tk()root.filename = filedialo ...
- LinuxC安装gcc
使用centos进行C编程的时候使用gcc hello.c提示 bash:gcc:command not found 此时需要给Linux安装gcc命令如下 1 yum -y install gcc ...
- U-Boot在FL2440上移植(四)----支持网卡DM9000和烧写yaffs文件系统
<一>支持网卡芯片DM9000 在driver下,有网卡驱动DM9000x.c 和 DM9000x.h DM9000接在BANK4,位宽16 在include/configs/TX2440 ...
- 亲测VS2010纯静态编译QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序(图文并茂,非常详细)
下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip,不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0- ...
- prim模板
]; int n; ][]; ]; int prim(){ int i,j,mi,v; ;i<n;i++){ d[i]=map[][i]; vis[i]=; } ;i<=n;i++){ m ...
- 关于PCA算法的一点学习总结
本文出处:http://blog.csdn.net/xizhibei ============================= PCA,也就是PrincipalComponents Analysis ...
- html里面自定义弹出窗口
网页上默认的提示框或对话框一般比较丑,可以利用div遮盖层来自定义对话框 1.定义一个按钮或者链接(项目里面是通过点击一个图片) <img src="images/zz.gif&quo ...
- CoinChange
题目 题目:CoinChange 有面额不等的coins,数量无限,要求以最少的\(coins\)凑齐所需要的\(amount\). 若能,返回所需的最少coins的数量,若不能,返回-1. Exam ...
- Xcode6中怎么添加空工程模板
亲们!是不是还在为Xcode中不能创建空工程模板苦恼,轩哥为大家准备了一个脚本,可以在Xcode6中直接创建空工程,跟以前一样一样的! 按照以下要求就可以了!下载地址:里面有一个文档有详细的步骤htt ...