CF GYM 100703B Energy Saving
题意:王子每月买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的更多相关文章
- Codeforces Gym 100269E Energy Tycoon 贪心
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
- 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 ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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 ...
- CF GYM 100703A Tea-drinking
题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...
- CF GYM 100703F Game of words
题意:两个人玩n个游戏,给出每人玩每个游戏的时间,两个人需要在n个游戏中挑m个轮流玩,求最短时间. 解法:dp.(这场dp真多啊……话说也可以用最小费用最大流做……然而并不会XD)dp[i][j][k ...
- CF GYM 100703G Game of numbers
题意:给n个数,一开始基数为0,用这n个数依次对基数做加法或减法,使基数不超过k且不小于0,输出最远能运算到的数字个数,输出策略. 解法:dp.dp[i][j]表示做完第i个数字的运算后结果为j的可能 ...
随机推荐
- asp 回发的时候样式变化
在一个按钮确定后弹出一个提示框,在提示框没有关闭时有时会发现页面的样式发生变化. 解决方法: 在DIV外增加,<table><tr><td align="lef ...
- strcmp的源码实现
微软方法: int __cdecl strcmp (const char *src, const char *dst) { ; while(!(ret = *(unsigned char *)src ...
- 【MyBatis】 通过包含的jdbcType类型
BIT FLOAT CHAR TIMESTAMP OTHER UNDEFINED TINYINT REAL V ...
- 在百万数据中找出重复的数据sql
select * from (select count(name) as isone, name from tbl_org_departments group by name) t where t.i ...
- EF4.1之覆盖EF的默认的约定
覆盖EF默认的约定可以通过两种方式: 1.拦截模型构建器,使用流畅的API 2.通过给 类添加标签 好的,我还用之前定义的订单类来做例子: public class Order { public in ...
- [搜片神器]BT管理程序数据库速度调试优化问题
DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr 谢谢园子 ...
- Windows下的Memcache安装与测试教程
Windows下的Memcache安装 1.下载memcache for windows. 下载地址:http://splinedancer.com/memcached-win32/,推荐下载bina ...
- spoj 1437
自己暴了一下不过 转一个 bfs... #include <cstdio> #include <vector> #include <queue> #incl ...
- C++11多线程教学(一)
本篇教学代码可在GitHub获得:https://github.com/sol-prog/threads. 在之前的教学中,我展示了一些最新进的C++11语言内容: 1. 正则表达式(http://s ...
- &&运算符和||运算符的优先级问题
package priority; public class TestAndOrPriority { /* * &&的优先级高就不代表 他会先运行 ||的右边 而是说会把右边用& ...