COJ 1156 Switching bulbs
一道模拟题目
对于所有0 还是 1 我们都可以想象做均为 0 的状态
v[i]表示原来的值
但是对于原来为1的要加上其所在的值作为初始值
然后转化后 a[i] = -v[i] , 如果原来为0 , 那就直接赋值
我们总是希望将尽可能大的值先加 ,所以将a由大到小排个序 , 一直加到负数的时候需要考虑这个负数取不取,其实我们最多取一个负数,因为当加了
第一个负数若后面还为负数,那么我们可以将那个负数倒转又加回来即可
但第一个负数取不取也要看它的绝对值是不是比前一个数大,如果大,说明宁可将前一个数再变一次颜色后舍去也不需要加后一个负数
最后我们就确定实际上使用的数了,如果操作数大于这个数,说明超过范围只是不断的将最小的数不断改变颜色
#include <cstdio>
#include <algorithm>
using namespace std; const int N = ;
int col[N] , v[N] , a[N]; bool cmp(int a , int b)
{
return a>b;
} int main()
{
// freopen("a.in" , "r" , stdin);
int n , m;
while(scanf("%d%d" , &n , &m) == )
{
for(int i = ; i<n ; i++)
scanf("%d" , col+i);
for(int i = ; i<n ; i++)
scanf("%d" , v+i); int val = ;
for(int i= ; i<n ; i++)
if(col[i]){
val += v[i];
a[i] = -v[i];
}
else{
a[i] = v[i];
}
sort(a , a+n , cmp);
for(int i = ; i<n ; i++){
if(a[i] < ){
if(i == ){
n = ;
break;
}
if(-a[i] > a[i-]) n = i;
else n = i+;
break;
}
}
if(m<=n){
for(int i = ; i<m ; i++)
val += a[i];
}
else{
for(int i = ; i<n ; i++){
val += a[i];
}
if((m-n)&) val -= a[n-];
}
printf("%d\n" , val);
}
return ;
}
COJ 1156 Switching bulbs的更多相关文章
- Disable the screen switching about VI
If you want to disable the screen switching, and you don't want tochange your termcap, you can add t ...
- Multiprotocol Label Switching (MPLS)
Posted by: Margaret Rouse WhatIs.com Contributor(s): Robert Sturt This definition is part of our E ...
- ural 1156. Two Rounds
1156. Two Rounds Time limit: 2.0 secondMemory limit: 64 MB There are two rounds in the Urals Champio ...
- FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)
FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS Memory Limit: 257792K [Description] [题目 ...
- Note for Computer Networks_Circuit Switching & Packet Switching
Packet Switching: - In a packet switched network data is transmitted in blocks(packets), typically l ...
- Cortex-M3 Context Switching
http://www.embedded.com/design/embedded/4231326/Taking-advantage-of-the-Cortex-M3-s-pre-emptive-cont ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- HDU 5601 N*M bulbs 找规律
N*M bulbs 题目连接: http://codeforces.com/contest/510/problem/C Description NM个灯泡排成一片,也就是排成一个NM的矩形,有些开着, ...
- BestCoder Round #67 (div.2) N bulbs(hdu 5600)
N bulbs Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
随机推荐
- 基于Linux系统的Shell编程-基础篇
1. Shell基础介绍 1.1 Shell编程的意义 为什么使用shell编程 节约时间 1.2 显示脚本执行过程 前面有+表示执行过的命令的 前面没有东西,表示输出到屏幕上的内容. [root@C ...
- html表格合并单元格
th标签 合并列 colspan="k" 合并行 rowspan="k" 例子<th colspan="2", rowspan=& ...
- JavaScript--DOM节点属性
节点属性 在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType ...
- 题解报告:poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- ACM_走楼梯Ⅱ
走楼梯Ⅱ Time Limit: 2000/1000ms (Java/Others) Problem Description: 有一楼梯共N+1级,刚开始时你在第一级,若每次能走M级(1<=M& ...
- leetcode375 Guess Number Higher or Lower II
思路: dp. https://leetcode.com/problems/guess-number-higher-or-lower-ii/discuss/ 实现: class Solution { ...
- C++帮助文档(自己写的)
以下所有记录几乎都是摘抄自<C++ primer 5th 中文> auto 类型说明符 P61 特点: 1. 定义的变量必须有初始值 2. 通过初始值来推算变量的类 ...
- Python学习笔记之默认参数
函数定义时 参数定义的顺序必须是:必选参数.默认参数.可变参数和关键字参数. def test(a,b,c=1,*d,**e) pass
- SpringMVC中Controller类的方法返回String不跳转,而是将字符串显示到页面
问题描述: 在spring中,控制层的注解一般都是使用@Controller,如果哪个请求参数需要返回数据的话,我们可以在该方法上配合@ResponseBody注解使用,这也是比较常见的方式了. 今天 ...
- Angular——依赖注入
基本介绍 1.AngularJS采用模块化的方式组织代码,将一些通用逻辑封装成一个对象或函数,实现最大程度的复用,这导致了使用者和被使用者之间存在依赖关系. 2.所谓依赖注入是指在运行时自动查找依赖关 ...