题目大意:

n波人去k*k的电影院看电影。

要尽量往中间坐,往前坐。

直接枚举,贪心,能坐就坐,坐在离中心近期的地方。

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <algorithm>
  5. #define maxn 1000005
  6. #define lowbit(x) (x&(-x))
  7.  
  8. using namespace std;
  9.  
  10. struct BIT
  11. {
  12. int sum;
  13. void init(){sum=0;}
  14. }bit[105][105];
  15. int q,n;
  16. int Sum(int row,int x)
  17. {
  18. int ret=0;
  19. for(int i=x;i>=1;i-=lowbit(i))
  20. ret+=bit[row][i].sum;
  21. return ret;
  22. }
  23. int query(int row,int l,int r)
  24. {
  25. return Sum(row,r)-Sum(row,l-1);
  26. }
  27. void update(int row,int x)
  28. {
  29. for(int i=x;i<=n;i+=lowbit(i))
  30. bit[row][i].sum++;
  31. }
  32. int cal(int s,int e)
  33. {
  34. return (s+e)*(e-s+1)/2;
  35. }
  36. int main()
  37. {
  38. scanf("%d%d",&q,&n);
  39. int cen=n/2+1;
  40.  
  41. for(int i=0;i<=n;i++)
  42. for(int j=0;j<=n;j++)
  43. {
  44. bit[i][j].init();
  45. }
  46. for(int i=1;i<=q;i++)
  47. {
  48. int num;
  49. scanf("%d",&num);
  50. int ansr=-1,ansc=-1;
  51. int min_val=0x3f3f3f3f;
  52.  
  53. for(int r=1;r<=n;r++)
  54. {
  55. for(int c=1;c+num-1<=n;c++)
  56. {
  57. if(query(r,c,c+num-1)==0)
  58. {
  59. int tmp;
  60. if(c>=cen)
  61. {
  62. tmp=cal(c,c+num-1)-cen*num+abs(r-cen)*num;
  63. }
  64. else if(c+num-1<=cen)
  65. {
  66. tmp=cen*num-cal(c,c+num-1)+abs(r-cen)*num;
  67. }
  68. else
  69. {
  70. tmp=abs(r-cen)*num+cal(cen,c+num-1)-(c+num-cen)*cen+cen*(cen-c)-cal(c,cen-1);
  71. }
  72. if(tmp<min_val)
  73. {
  74. min_val=tmp;
  75. ansr=r;
  76. ansc=c;
  77. }
  78. }
  79. }
  80. }
  81. if(min_val!=0x3f3f3f3f)
  82. {
  83. printf("%d %d %d\n",ansr,ansc,ansc+num-1);
  84. for(int j=ansc;j<=ansc+num-1;j++)
  85. update(ansr,j);
  86. }
  87. else puts("-1");
  88. }
  89. return 0;
  90. }

Codeforces Beta Round #10 B. Cinema Cashier (树状数组)的更多相关文章

  1. Codeforces Beta Round #10 B. Cinema Cashier 暴力

    B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...

  2. Educational Codeforces Round 10 D. Nested Segments (树状数组)

    题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...

  3. 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 ...

  4. Codeforces Round #261 (Div. 2) D 树状数组应用

    看着题意:[1,i]中等于a[i]的个数要大于[,jn]中等于a[j]的个数 且i<j,求有多少对这种(i,j)  ,i<j可是 i前面的合法个数 要大于j后面的 看起来非常像逆序数的样子 ...

  5. Codeforces 703D Mishka and Interesting sum(树状数组+扫描线)

    [题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...

  6. 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 ...

  7. CodeForces 380C Sereja and Brackets(扫描线+树状数组)

    [题目链接] http://codeforces.com/problemset/problem/380/C [题目大意] 给出一个括号序列,求区间内左右括号匹配的个数. [题解] 我们发现对于每个右括 ...

  8. CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)

    树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且代码量和常数较小 首先定义一个数组 int c[N]; 并清空 memset(c, 0, sizeof c) ...

  9. 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 ...

随机推荐

  1. NOIP2014解题报告

    day 1 1.生活大爆炸版石头剪刀布(rps) 直接按照题意模拟即可 #include<cstdio> #include<algorithm> #include<cst ...

  2. Android 开发笔记 “调用WebService”

    WebService是一种基于SOAP协议的远程调用标准,通过webservice可以将不同操作系统平台.不同语言.不同技术整合到一块.在Android SDK中并没有提供调用WebService的库 ...

  3. linux命令行后台运行与调回

     直接ctrl+z  这个是暂时到后台执行   要调回来  输入  fg 

  4. [LeetCode]题解(python):024-Swap Nodes in Pairs

    题目来源: https://leetcode.com/problems/swap-nodes-in-pairs/ 题意分析: 给定一个链表,每两个相邻节点就行交换.比如1->2->3-&g ...

  5. poj 1430 第二类斯特林数

    1 #include <iostream> #include <cmath> #include <algorithm> using namespace std; i ...

  6. java和C#之间SOCKET通信的问题

    转自:http://www.cdtarena.com/javapx/201307/9170.html java和C#之间SOCKET通信的问题 一.服务器端(使用java编写) /** * 监听客户端 ...

  7. Qt之QNetworkInterface(查询网络接口),QHostInfo(查询主机IP)

    http://blog.csdn.net/u011012932/article/details/50775052 http://blog.csdn.net/u011012932/article/det ...

  8. ThinkPHP 3.1.2 模板的使用技巧

    本节课大纲: 一.模板包含 <include file="完整模板文件名" /> <include file="./Tpl/default/Public ...

  9. poj 1256 Anagram(dfs)

    题目链接:http://poj.org/problem?id=1256 思路分析:该题为含有重复元素的全排列问题:由于题目中字符长度较小,采用暴力法解决. 代码如下: #include <ios ...

  10. [对话CTO]当当网熊长青:兴趣是成为优秀工程师的第一因素-CSDN.NET

    Women Techmaker 北京站 [对话CTO]当当网熊长青:兴趣是成为优秀工程师的第一因素-CSDN.NET     [对话CTO]当当网熊长青:兴趣是成为优秀工程师的第一因素    发表于2 ...