zoukankan      html  css  js  c++  java
  • 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
    ", ans[x][0], ans[x][1]);
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    移动端字体单位
    我像素的理解
    了解viewport概念
    移动端知识
    本地存储和会话存储
    一屏滚动滚轮事件
    关于jquery的笔记
    关于bind()方法
    [css] 滚动条样式问题
    [element-ui] 表格功能实现(删除选中)
  • 原文地址:https://www.cnblogs.com/Apro/p/4685866.html
Copyright © 2011-2022 走看看