题意:王子每月买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. NSInvocation的使用(转)

    转载自:http://www.cnblogs.com/pengyingh/articles/2359199.html http://blog.iosxcode4.com/?p=125 在 iOS中可以 ...

  2. html template

    https://wrapbootstrap.com/tag/single-page http://themeforest.net/ https://wrapbootstrap.com/themes h ...

  3. 请求管道与IHttpModule接口

    IHttpModule向实现类提供模块初始化和处置事件.  IHttpModule包含兩個方法: public void Init(HttpApplication context);public vo ...

  4. 自定义Angular指令与jQuery实现的Bootstrap风格数据双向绑定的单选&多选下拉框

    先说点闲话,熟悉Angular的猿们会喜欢这个插件的. 00.本末倒置 不得不承认我是一个喜欢本末倒置的人,学生时代就喜欢先把晚交的作业先做,留着马上就要交的作业不做,然后慢悠悠做完不重要的作业,卧槽 ...

  5. [转]StructLayout特性

    转自:http://www.cnblogs.com/JessieDong/archive/2009/07/21/1527553.html StructLayout特性 StructLayout特性   ...

  6. 1048: [HAOI2007]分割矩阵 - BZOJ

    Description 将一个a*b的数字矩阵进行如下分割:将原矩阵沿某一条直线分割成两个矩阵,再将生成的两个矩阵继续如此分割(当然也可以只分割其中的一个),这样分割了(n-1)次后,原矩阵被分割成了 ...

  7. Windows下配置使用 MemCached

    Windows下配置使用MemCached 工具: memcached-1.2.6-win32-bin.zip     MemCached服务端程序(for win) Memcached Manage ...

  8. js key事件 keyCode大全

    keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 ...

  9. 分享SCI写作经验和一些工具

  10. spoj 394

    每段可以连续的串的可能性是个Fibonacci数列   但是直接dp更好吧~~ #include <cstdio> #include <cstring> using names ...