一道模拟题目

对于所有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的更多相关文章

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

  2. Multiprotocol Label Switching (MPLS)

    Posted by: Margaret Rouse WhatIs.com   Contributor(s): Robert Sturt This definition is part of our E ...

  3. ural 1156. Two Rounds

    1156. Two Rounds Time limit: 2.0 secondMemory limit: 64 MB There are two rounds in the Urals Champio ...

  4. FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

    FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目 ...

  5. Note for Computer Networks_Circuit Switching & Packet Switching

    Packet Switching: - In a packet switched network data is transmitted in blocks(packets), typically l ...

  6. Cortex-M3 Context Switching

    http://www.embedded.com/design/embedded/4231326/Taking-advantage-of-the-Cortex-M3-s-pre-emptive-cont ...

  7. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  8. HDU 5601 N*M bulbs 找规律

    N*M bulbs 题目连接: http://codeforces.com/contest/510/problem/C Description NM个灯泡排成一片,也就是排成一个NM的矩形,有些开着, ...

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

随机推荐

  1. python使用ddt模块对用例执行操作

    import time import unittest import ddt from selenium import webdriver TEST_URL = "http://www.ba ...

  2. JS自定义右键菜单案例

    要求:点击页面鼠标右键,阻止默认右键菜单的弹出,并弹出自定义右键菜单. 效果示例: 参考代码: <!DOCTYPE html> <html lang="zh-CN" ...

  3. Html 标签的事件绑定(转自 MSDN)

    参考 MSDN 网页给 HTML 标签绑定 click 事件: function makeFoldersCollapsible(folderIcon, openFolderIcon, pathToIc ...

  4. 红黑树与AVL(平衡二叉树)的区别

    关于红黑树和AVL树,来自网络: 1 好处 及 用途 红黑树 并不追求“完全平衡 ”——它只要求部分地达到平衡要求,降低了对旋转的要求,从而提高了性能. 红黑树能够以 O(log2  n)  的时间复 ...

  5. 【转】MySQL常见的运算符及使用

    转自:http://www.linuxidc.com/Linux/2016-03/129672.htm MySQL中有4类运算符,它们是: 算术运算符 比较运算符 逻辑运算符 位操作运算符 算术操作符 ...

  6. c# Queue实现生产者(Producer)消费者(Consumer)模式

    我们在开发过程中经常会遇到需要从一个地方不断获取数据然后又需要交给另一个线程对数据进行二次加工的情况,这种场景适合使用生产者-消费者模式. Demo展示 //中间的容器 public static c ...

  7. 8月中旬之后的学习计划 --- react

    这段时间快活了,放纵了,玩hi了,接下来该好好的学习新知识了. 鉴于目前业界比较火的前端js框架有react.vue,决定先从react开始学习.之前有简单的接触过它的一些基本的语法知识,这次准备全面 ...

  8. HDU_1505_矩阵中的最大矩形_dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 City Game Time Limit: 2000/1000 MS (Java/Others) ...

  9. 在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法

    在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法 [MXDRAW CAD控件文档] 下面帮助的完整例子,在控件安装目录的Sample\Ie\iedemo.htm中. 1.      主要用到 ...

  10. 01Hypertext Preprocessor

    Hypertext Preprocessor PHP即Hypertext Preprocessor是一种被广泛使用的开放源代码多用途动态交互性站点的强有力的服务器端脚本语言尤其适用于 Web开发人员可 ...