题意:王子每月买m个灯泡给n个房间换灯泡,如果当前有的灯泡数够列表的第一个房间换的就全换,直到灯泡不够为止,给出q个查询,查询x月已经换好几个房子,手里还剩多少灯泡。

解法:水题……小模拟。

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int a[1005], ans[100005][2];
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m))
{
int cnt = 0;
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
ans[0][0] = 0, ans[0][1] = 0;
int j = 0;
for(int i = 1; i <= 100000; i++)
{
cnt++;
ans[i][0] = ans[i - 1][0];
ans[i][1] = ans[i - 1][1] + m;
while(j < n && a[j] <= ans[i][1])
{
ans[i][0]++;
ans[i][1] -= a[j];
j++;
}
if(j == n)
break;
}
int q;
scanf("%d", &q);
while(q--)
{
int x;
scanf("%d", &x);
if(x > cnt)
x = cnt;
printf("%d %d\n", ans[x][0], ans[x][1]);
}
}
return 0;
}

  

CF GYM 100703B Energy Saving的更多相关文章

  1. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

  2. CF Gym 102028G Shortest Paths on Random Forests

    CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...

  3. CF gym 101933 K King's Colors —— 二项式反演

    题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...

  4. cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)

    题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...

  5. CF Gym 100685A Ariel

    传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. CF Gym 100685E Epic Fail of a Genie

    传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...

  7. CF GYM 100703A Tea-drinking

    题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...

  8. CF GYM 100703F Game of words

    题意:两个人玩n个游戏,给出每人玩每个游戏的时间,两个人需要在n个游戏中挑m个轮流玩,求最短时间. 解法:dp.(这场dp真多啊……话说也可以用最小费用最大流做……然而并不会XD)dp[i][j][k ...

  9. CF GYM 100703G Game of numbers

    题意:给n个数,一开始基数为0,用这n个数依次对基数做加法或减法,使基数不超过k且不小于0,输出最远能运算到的数字个数,输出策略. 解法:dp.dp[i][j]表示做完第i个数字的运算后结果为j的可能 ...

随机推荐

  1. php 如何开启session

    1.如果你在session_start()前没有输出内容,哪怕是一个句号也不行,就可以直接使用session_start)_; 2.如果你之前已经有输出内容了,可以使用以下方法: <?php o ...

  2. 遍历并修改dictionary的值

    var dictionary = clb_Select.Items.Cast<object>().ToDictionary(item => item.ToString(), item ...

  3. NSFileManager 沙盒文件管理

    文件夹创建,复制,移动,删除,检查是否存在,代码如下: 1.获取沙盒 document 路径,作为文件夹路径的基路径. NSString *document = NSSearchPathForDire ...

  4. C# Path

    http://hi.baidu.com/mayijun0410/item/4fa6c6c154a1c35ebdef69f9 using System.IO; Path类的静态方法: ChangeExt ...

  5. 现代浏览器原生js获取id号方法

    <div id="tests" class="a b c" style="color:#f00">123</div> ...

  6. 团体程序设计天梯赛-练习集L2-010. 排座位

    L2-010. 排座位 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位. ...

  7. Flume的Avro Sink和Avro Source研究之一: Avro Source

    问题 : Avro Source提供了怎么样RPC服务,是怎么提供的? 问题 1.1 Flume Source是如何启动一个Netty Server来提供RPC服务. 由GitHub上avro-rpc ...

  8. openssl安装问题导致nginx添加ssl模块失败

    问题:./nginx: undefined symbol: EVP_rc4_hmac_md5 sudo vi /etc/ld.so.conf #把openssl安装路径加入sudo ldconfig ...

  9. 易企秀 we+ Maka 兔展 四大H5页面制作工具

    H5这个由HTML5简化而来的词汇,正通过微信广泛传播.H5是集文字.图片.音乐.视频.链接等多种形式的展示页面,丰富的控件.灵活的动画特效.强大的交互应用和数据分析,高速低价的实现信息传播,非常适合 ...

  10. 编程之美 3.1 字符串移位包含问 复杂度(O(N*K)

    分享关于编程之美3.1自己编写的代码,很简单. s2.沿着s1匹配(循环匹配,利用%Length技巧),匹配上,返回true. //BOP3.1 char src[] = "AABBCD&q ...