Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

新手参考,大神勿进

Posted by 2004140022 at 2015-11-19 17:44:42 on Problem 2459
题意是这样的:c只牛,每只每天吃 1 KG 饲料,每只牛都有一个出现时间,start 和end ,当然在添加饲料之前它是不会吃主人的饲料的(不知道它是怎么活下来的--!),添加饲料之后,每天吃 1 KG,当然你要判断D天在那只牛离开之前还是之后,(离开之后的话,额,它不会吃饲料)。
主人在第 N 天 添加了饲料 f1 KG,在第 D 天还剩下 f2 KG 饲料。求N.
啰里啰唆的半天,其实解决很简单,你把每天牛要吃的饲料加起来,知道D,向前遍历,f1-f2就是吃掉的饲料值,当变成0 时,那天肯定就是添加饲料的那天。

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<algorithm>
#define N 2001
using namespace std;
int s[N];
int main()
{
    int i,j,c,f1,f2,d,m,n;
    scanf("%d%d%d%d",&c,&f1,&f2,&d);
    memset(s,0,sizeof(s));
    for(i=0;i<c;i++)
    {
        scanf("%d%d",&m,&n);
        for(j=m;j<=n;j++) s[j]++;
    }
    f1-=f2;
    for(i=d;i>=1;i--)
    {
        f1-=s[i];
        if(f1==0)break;
    }
    printf("%d\n",i);
return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator