zoukankan      html  css  js  c++  java
  • POJ 3273

    Monthly Expense
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 12122   Accepted: 4932

    Description

    Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.

    FJ wants to create a budget for a sequential set of exactly M (1 ≤ MN) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.

    FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.

    Input

    Line 1: Two space-separated integers: N and M
    Lines 2..N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day

    Output

    Line 1: The smallest possible monthly limit Farmer John can afford to live with.

    Sample Input

    7 5
    100
    400
    300
    100
    500
    101
    400

    Sample Output

    500

    Hint

    If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. Any other method of scheduling gives a larger minimum monthly limit.

    Source

     
    二分枚举
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <iostream>
     5 
     6 using namespace std;
     7 
     8 #define maxn 100005
     9 
    10 int n,m;
    11 int money[maxn];
    12 
    13 bool judge(int x) {
    14         int need = n - m,now;
    15         for(int i = 1; i <= n; i++) {
    16                 if(now + money[i] <= x) {
    17                         if(now != 0) --need;
    18                         now += money[i];
    19                 } else {
    20                         now = money[i];
    21                 }
    22 
    23         }
    24 
    25         return need <= 0;
    26 }
    27 
    28 void solve() {
    29         int l = 0,r = 0;
    30 
    31         for(int i = 1; i <= n; i++) {
    32                 l = max(l,money[i]);
    33                 r += money[i];
    34         }
    35 
    36         while(l < r) {
    37                 int mid = (l + r) >> 1;
    38                 if(judge(mid)) {
    39                         r = mid;
    40                 } else {
    41                         l = mid + 1;
    42                 }
    43         }
    44 
    45         printf("%d
    ",l);
    46 }
    47 int main() {
    48       //  freopen("sw.in","r",stdin);
    49 
    50         scanf("%d%d",&n,&m);
    51         for(int i = 1; i <= n; i++) {
    52                 scanf("%d",&money[i]);
    53         }
    54 
    55         solve();
    56 
    57         return 0;
    58 }
    View Code
  • 相关阅读:
    目标检测应用化之web页面(YOLO、SSD等)
    传统候选区域提取方法
    非极大值抑制(Non-Maximum Suppression,NMS)
    Darknet windows移植(YOLO v2)
    线性判别分析 LDA
    SVM 支持向量机
    特征-相似度衡量
    布隆过滤器 Bloom Filter
    聚类算法
    图论--最大流
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3599189.html
Copyright © 2011-2022 走看看