PDA

View Full Version : يک سوال acm



lvlina_r
شنبه 17 بهمن 1388, 15:38 عصر
سلام
د رحل سوال acm به مشکلي بر خوردم به اين نتيجه رسيدم که اينجا بهترين مکان براي حل آن هاست.
سوال ضميمه شده........
من فکر کردم بايد اشتراک بازه ها را بگيرم و حاصل را محاسبه کنم ولي به نتيجه اي نرسيدم، لطفا مرا راهنمايي کنيد......

a.gh.n
چهارشنبه 21 بهمن 1388, 01:48 صبح
#include <iostream>
using std::cin;
using std::cout;

int main()
{
int n; //number of airplanes
cin >> n;
do
{
int* lowerbound=new int [n];
int* upperbound=new int [n];
int mingap=1440; //answer in seconds
static int tc=1;

cin >> lowerbound[0] >> upperbound[0];
lowerbound[0]*=60;
upperbound[0]*=60;

for (int i=1; i<n; i++)
{
cin >> lowerbound[i] >> upperbound[i];
lowerbound[i]*=60;
upperbound[i]*=60;
if (lowerbound[i]-lowerbound[i-1]<mingap)
mingap = (lowerbound[i]-lowerbound[i-1]);
}
bool caninc=true;
while (caninc)
{
mingap++;
for (int i=1; i<n; i++)
if (lowerbound[i-1]+mingap <= upperbound[i])
lowerbound[i]++;
else //BOOM!
{
caninc=false;
break;
}
}

mingap--;
cout << "Case " << tc << ": " << mingap/60 << ':' << mingap%60 << '\n';
delete [] lowerbound; //freak memory
delete [] upperbound;
tc++;
cin >> n;
} while (n);
return 0;
}

aasmass
یک شنبه 15 فروردین 1389, 20:35 عصر
ميشه صورت سوال رو بنويسيد؟؟؟؟؟؟