zoukankan      html  css  js  c++  java
  • 【CF1016A】Death Note(签到)

    题意:无限页的书,每页可以写m个名字,给你一个长度为n的序列,序列为你每天要写的名字数,输出你每天要翻的页数。 

    n<=2e5,m,a[i]<=1e9

    思路:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define MOD 1000000007
    21 #define N   210000
    22 
    23 ll a[N],b[N];
    24 ll n,m;
    25 
    26 int read()
    27 { 
    28    int v=0,f=1;
    29    char c=getchar();
    30    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    31    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    32    return v*f;
    33 }
    34 
    35  
    36 int main()
    37 {
    38       //freopen("1.in","r",stdin);
    39     //freopen("1.out","w",stdout);
    40     scanf("%d%d",&n,&m);
    41     for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    42     ll now=0,sum=0;
    43     ll ans=0;
    44     for(int i=1;i<=n;i++) 
    45     {
    46         if(now+a[i]<m) {now+=a[i];b[i]=ans;}
    47          else
    48          {
    49              a[i]-=(m-now);
    50              ans++;
    51             ans+=(a[i]/m);
    52             now=a[i]%m; 
    53              b[i]=ans;
    54          }
    55     }
    56     for(int i=1;i<=n;i++) printf("%lld ",b[i]-b[i-1]);
    57     return 0;
    58 }
  • 相关阅读:
    NYOJ 1073 最大值 (模拟)
    NYOJ 1063 生活的烦恼 (二叉树)
    NYOJ 1022 合纵连横 (并查集)
    [leetcode-553-Optimal Division]
    [leetcode-496-Next Greater Element I]
    [leetcode-556-Next Greater Element III]
    [leetcode-500-Keyboard Row]
    [leetcode-36-Valid Sudoku]
    [leetcode-127-Word Ladder]
    [leetcode-567-Permutation in String]
  • 原文地址:https://www.cnblogs.com/myx12345/p/9843001.html
Copyright © 2011-2022 走看看