BZOJ4045 : [Cerc2014] bricks
首先求出B和W的个数,如果只出现了一种那么直接输出sum(k)。
否则依次扫描,能割就割,时间复杂度$O(n)$。
#include<cstdio>
#define N 100010
typedef long long ll;
int T,n,i,a[N],b[N],c[2],d[2],ans;ll x;char s[2];
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
c[0]=c[1]=d[0]=d[1]=ans=0;
for(i=1;i<=n;i++)scanf("%d%s",&b[i],s),a[i]=s[0]=='B',c[a[i]=s[0]=='B']+=b[i];
if(!c[0]||!c[1]){printf("%d\n",c[0]+c[1]);continue;}
for(i=1;i<=n;i++){
x=(ll)c[a[i]]*d[a[i]^1]-(ll)d[a[i]]*c[a[i]^1];
if(x%c[a[i]^1]||x<=0||x/c[a[i]^1]>b[i])d[a[i]]+=b[i];
else ans++,d[a[i]]=b[i]-x/c[a[i]^1],d[a[i]^1]=0;
}
printf("%d\n",ans);
}
return 0;
}
BZOJ4045 : [Cerc2014] bricks的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Box of Bricks最小移动砖块数目
Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...
- Codeforces Gym 100002 B Bricks 枚举角度
Problem B Bricks" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 ...
- [POJ1477]Box of Bricks
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19503 Accepted: 7871 Description Litt ...
- HDOJ(HDU) 2088 Box of Bricks(平均值)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- HDOJ 1326 Box of Bricks(简单题)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- 591 - Box of Bricks
Box of Bricks Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...
- Box of Bricks
Box of Bricks Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
随机推荐
- Spark记录-官网学习配置篇(二)
### Spark SQL Running the SET -v command will show the entire list of the SQL configuration. #scala/ ...
- SQL记录-PLSQL触发器
PL/SQL触发器 触发器是存储程序,它会自动执行或发射当一些事件发生.触发器,事实上,写入响应于以下任一事件将被执行: 数据库操作(DML)语句(DELETE,INSERT,UPDATE或) 数据库 ...
- bzoj千题计划290:bzoj3143: [Hnoi2013]游走
http://www.lydsy.com/JudgeOnline/problem.php?id=3143 计算每条边经过的概率e[] 然后经过概率多的分配的编号大,经过概率少的分配的编号小 如何计算边 ...
- 洛谷P2326 AKN’s PPAP
https://www.luogu.org/problemnew/show/P2326 按位贪心 找到最高位&1的数,确定次高位的时候只从最高位&1的数里选 此次类推 #include ...
- .NET面试题系列(六)多线程
1.多线程的三个特性:原子性.可见性.有序性 原子性:是指一个操作是不可中断的.即使是多个线程一起执行的时候,一个操作一旦开始,就不会被其他线程干扰. 比如,对于一个静态全局变量int i,两个线程同 ...
- jQuery下ajax事件的简单分析
昨天写了一篇关于监视页面动态生成元素问题的文章,引起了一些小小的争议,不过我从中学到了很多.文章在这,<jQuery下实现等待指定元素加载完毕>当然 动态生成的节点元素 分很多种情况,这里 ...
- unp的hello word
最近无聊,再学学unp吧.学学网络编程.下面是一个demo: intro/daytimetcpcli.c #include "unp.h" int main(int argc, c ...
- Spark笔记之Catalog
一.什么是Catalog Spark SQL提供了执行sql语句的支持,sql语句是以表的方式组织使用数据的,而表本身是如何组织存储的呢,肯定是存在一些元数据之类的东西了,Catalog就是Spark ...
- int,char指针探究
#include<iostream> using namespace std; int main() { /* 思路: 1.关于int指针,不可以直接往指针里传值 例:int *a = 4 ...
- 使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)
本文记录了我使用Cobbler批量安装部署Linux和Windows系统的过程,文章主要分为三部分:Cobbler服务端的安装配置.Linux发行版CentOS和Ubuntu的自动安装部署.Windo ...