codeforces #413 A. Carrot Cakes (模拟)

题目链接

题意:初始有一个锅,每t分钟可以做好k个饼,现在需要N个饼。还可以另外建一个锅,花费d时间,建好以后两个锅可以并行烙饼。问是否应该建锅?(以期减少烙饼时间)

思路:求出两种情况下的总时间,比较一下。

只有一个锅的情况很好求。

两个锅的情况比较麻烦,不如模拟时间流逝?

反正最多也就1E6的时间。。。模拟一下。。。稳。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2017年05月11日 星期四 15时29分43秒
 4File Name :A.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define PB push_back
20#define fst first
21#define sec second
22#define lson l,m,rt<<1
23#define rson m+1,r,rt<<1|1
24#define ms(a,x) memset(a,x,sizeof(a))
25typedef long long LL;
26#define pi pair < int ,int >
27#define MP make_pair
28
29using namespace std;
30const double eps = 1E-8;
31const int dx4[4]={1,0,0,-1};
32const int dy4[4]={0,-1,1,0};
33const int inf = 0x3f3f3f3f;
34int main()
35{
36	#ifndef  ONLINE_JUDGE 
37	freopen("code/in.txt","r",stdin);
38  #endif
39	int n,t,k,d;
40	int ans1,ans2;
41	cin>>n>>t>>k>>d;
42	ans1 = ((n-1)/k+1)*t;
43	int num1 = 0 ;
44	for ( int i = 1 ; i <= 200000 ; i++)
45	{
46	    if (i%t==0) num1+=k;
47	    if (num1>=n) 
48	    {
49		ans2 = i ;
50		break;
51	    }
52	    if (i>=d)
53	    {
54		int ii = i-d;
55		if (ii%t==0&&ii>0) num1+=k;
56		if (num1>=n)
57		{
58		    ans2 = i;
59		    break;
60		}
61	    }
62	}
63//	ans2+=d;
64	cout<<"ans1:"<<ans1<<"ans2:"<<ans2<<endl;
65	if (ans1>ans2) puts("YES");
66	else puts("NO");
67
68
69  #ifndef ONLINE_JUDGE  
70  fclose(stdin);
71  #endif
72    return 0;
73}