Pagini recente »
Profil HedeaMihneA
|
12345qwerty
|
Atașamentele paginii 2015-11-17-clasa-6-tema-8
|
Statistici Cristian Andrei Popescu (kikiandrei)
|
Cod sursă (job #671776)
Cod sursă (job
#671776)
#include <bits/stdc++.h>
#define L 5e6 + 5
#define FAIL L + 1
using namespace std;
ifstream fin("scv.in");
ofstream fout("scv.out");
long long costNewSCV, timeNewSCV, productionSCV, goalProduction;
long long currentTime, currentSCV, minerals, totalSCV;
bool success;
inline void startProcess(long long numberOfSCV);
inline void status_1();
inline void status_2();
inline void status_3();
inline void status_4();
inline void status_5();
inline void status_6();
inline void startProcess(long long numberOfSCV){
totalSCV = numberOfSCV;
currentTime = minerals = 0;
currentSCV = 1;
///cout << "PROCESS STARTED!\n";
status_1();
if (!success)
currentTime = FAIL;
}
inline void status_1(){
///cout << "STATUS_1 was triggered!\n";
///cout << "CURRENT_TIME = " << currentTime << "\n";
if (currentSCV < totalSCV)
status_2();
else
status_3();
}
inline void status_2(){
///cout << "STATUS_2 was triggered!\n";
if (currentTime > L){
///cout << "STATUS_2 triggered FAIL!\n";
status_6();
}
else if (minerals < costNewSCV){
minerals = minerals + currentSCV * productionSCV;
currentTime++;
status_2();
}
else{
minerals -= costNewSCV;
status_5();
}
}
inline void status_3(){
///cout << "STATUS_3 was triggered!\n";
if (currentTime > L){
///cout << "STATUS_3 triggered FAIL!\n";
status_6();
}
else if (minerals < goalProduction){
minerals = minerals + currentSCV * productionSCV;
currentTime++;
status_3();
}
else
status_4();
}
inline void status_4(){
///cout << "SUCCESS!\n";
success = true;
}
inline void status_5(){
long long i;
bool failed = false;
///cout << "STATUS_5 was triggered!\n";
for (i = 0; i < timeNewSCV; i++){
if (currentTime > L){
i = timeNewSCV;
failed = true;
}
minerals = minerals + currentSCV * productionSCV;
currentTime++;
}
if (failed){
///cout << "STATUS_5 triggered FAIL!\n";
status_6();
}
else{
currentSCV++;
status_1();
}
}
inline void status_6(){
///cout << "FAIL!\n";
success = false;
}
int main(){
long long le, ri, mid1, mid2, best, time1, time2;
fin >> costNewSCV >> timeNewSCV >> productionSCV >> goalProduction;
/**
startProcess(3);
cout << currentTime << "\n";
**/
/**/
le = best = 1;
ri = goalProduction + 1;
while (le <= ri){
mid1 = le + (ri - le) / 3;
mid2 = le + 2 * (ri - le) / 3;
///cout << "Process was started for " << mid1 << ".\n";
startProcess(mid1);
time1 = currentTime;
///cout << "CurrentTime is " << time1 << ".\n\n";
///cout << "Process was started for " << mid2 << ".\n";
startProcess(mid2);
time2 = currentTime;
///cout << "CurrentTime is " << time2 << ".\n\n";
if (time1 < time2){
best = time1;
ri = mid2 - 1;
}
else{
best = time2;
le = mid1 + 1;
}
}
fout << best << "\n";
/**/
return 0;
}