codeforces #413 A. Carrot Cakes (模拟)

题目链接

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

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

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

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

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

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