![:(](./images/smilies/icon_frown.gif)
I've tried all the inputs in this forum and all of them were ok... If anyone could send me some critical input/output that would really help! ty
Here's my code:
Code: Select all
removed after AC
Moderator: Board moderators
Code: Select all
removed after AC
Code: Select all
/*************************************************************************
* Copyright (C) 2008 by Moustafa Mahmoud (cmpsamurai) *
* moustafa@cmpsamurai.com *
*************************************************************************/
/*C++ "10037 - Bridge" */
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <iterator>
#include <sstream>
using namespace std;
void cross(deque<int> runners)
{
deque<int> first,second;
first=runners;
int time=0;
stringstream output;
int temp=-1,last1,last2;
while(second.size()<runners.size())
{
sort(first.begin(),first.end());
sort(second.begin(),second.end());
if(first.size()==1)
{
output<<first.front()<<endl;
time+=first.front();
second.push_front(first.front());
first.pop_front();
}
else if(first.size()==2)
{
output<<first[0]<<" "<<first[1]<<endl;
time+=first[1];
second.push_back(first.front());
first.pop_front();
second.push_back(first.front());
first.pop_front();
}
else if(first.size()==3)
{
output<<first[0]<<" "<<first[2]<<endl;
time+=first[2];
second.push_back(first[0]);
second.push_front(first[2]);
first.pop_front();
first.pop_back();
sort(second.begin(),second.end());
output<<second[0]<<endl;
time+=second[0];
output<<second[0]<<" "<<first[0]<<endl;
time+=first[0];
second.push_back(first[0]);
}
else
{
bool test1=(first[1]+first[0]+first[first.size()-2]+first[1])<(first[0]+first[0]+first[first.size()-1]+first[first.size()-2]);
if(test1)
{
//first 2
output<<first[0]<<" "<<first[1]<<endl;
time+=first[1];
second.push_back(first[0]);
second.push_back(first[1]);
first.pop_front();
first.pop_front();
sort(second.begin(),second.end());
first.push_front(second[0]);
output<<second[0]<<endl;
time+=second[0];
second.pop_front();
//last 2
output<<first[first.size()-2]<<" "<<first[first.size()-1]<<endl;
time+=first[first.size()-1];
second.push_back(first[first.size()-2]);
second.push_back(first[first.size()-1]);
first.pop_back();
first.pop_back();
first.push_front(second.front());
time+=first.front();
output<<first.front()<<endl;
second.pop_front();
}
else
{
//first 2
output<<first[0]<<" "<<first[first.size()-1]<<endl;
time+=first[first.size()-1];
second.push_back(first[0]);
second.push_back(first[first.size()-1]);
first.pop_front();
first.pop_back();
sort(second.begin(),second.end());
first.push_front(second[0]);
output<<second[0]<<endl;
time+=second[0];
second.pop_front();
//last 2
output<<first[0]<<" "<<first[first.size()-1]<<endl;
time+=first[first.size()-1];
second.push_back(first[0]);
second.push_back(first[first.size()-1]);
first.pop_back();
first.pop_front();
sort(second.begin(),second.end());
first.push_front(second.front());
time+=first.front();
output<<first.front()<<endl;
second.pop_front();
}
}
}
cout<<time<<endl;
cout<<output.str();
}
int main() {
int num_cases,n,temp;
string line;
cin>>num_cases;
getline(cin,line);
for(int i=0;i<num_cases;i++)
{
getline(cin,line);
cin>>n;
cin.ignore();
deque<int> speeds;
for(int j=0;j<n;j++)
{
cin>>temp;
cin.ignore();
speeds.push_back(temp);
}
cross(speeds);
if(i<num_cases-1)
{
cout<<endl;
}
}
return 0;
}
Code: Select all
1
40
35
56
72
18
26
63
26
47
18
81
69
60
84
90
90
74
33
40
45
4
36
10
38
61
84
6
41
100
57
100
91
43
7
62
60
32
76
37
30
46
Code: Select all
1349
4 6
4
100 100
6
4 6
4
90 91
6
4 6
4
84 90
6
4 6
4
81 84
6
4 6
4
74 76
6
4 6
4
69 72
6
4 6
4
62 63
6
4 6
4
60 61
6
4 6
4
57 60
6
4 6
4
47 56
6
4 6
4
45 46
6
4 6
4
41 43
6
4 6
4
38 40
6
4 6
4
36 37
6
4 6
4
33 35
6
4 6
4
30 32
6
4 6
4
26 26
6
4 6
4
18 18
6
4 10
4
4 7
4
4 6
Code: Select all
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void check();
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
check();
}
system("pause");
}
void check()
{
int num;
int tmp;
vector<int> people;
string text;
int count = 0;
ostringstream os;
cin >> num;
for (int i = 0; i < num;i++)
{
cin >> tmp;
people.push_back(tmp);
}
int smallest, secondSmallest;
sort(people.begin(), people.end());
if (num == 1)
{
os << people[0] << endl;
text = os.str();
count = people[0];
cout << count << endl << text;
return;
}
else if (num == 2)
{
count = people[1];
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
return;
}
else if (num == 3)
{
count = people[0] + people[1] + people[2];
os << people[0] << " " << people[2] << endl;
os << people[0] << endl;
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
return;
}
smallest = people[0];
secondSmallest = people[1];
if (num %2 ==1)
{
for (int i = num - 1; i != 2; i -= 2)
{
os << smallest << " " << secondSmallest << endl;
count = count + secondSmallest;
os << smallest << endl;
count = count + smallest;
os << people[i-1] << " " << people[i ] << endl;
count = count + people[i];
os << secondSmallest << endl;
count = count + secondSmallest;
}
count += people[0] + people[1] + people[2];
os << people[0] << " " << people[2] << endl;
os << people[0] << endl;
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
}
else
{
for (int i = num - 1; i != 1; i -= 2)
{
os << smallest << " " << secondSmallest << endl;
count = count + secondSmallest;
os << smallest << endl;
count = count + smallest;
os << people[i-1] << " " << people[i ] << endl;
count = count + people[i];
os << secondSmallest << endl;
count = count + secondSmallest;
}
count += people[1];
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
}
}
Code: Select all
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void check();
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
check();
}
}
void check()
{
int num;
int tmp;
vector<int> people;
string text;
int count = 0;
ostringstream os;
cin >> num;
for (int i = 0; i < num;i++)
{
cin >> tmp;
people.push_back(tmp);
}
int smallest, secondSmallest;
sort(people.begin(), people.end());
if (num == 1)
{
os << people[0] << endl;
text = os.str();
count = people[0];
cout << count << endl << text;
return;
}
else if (num == 2)
{
count = people[1];
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
return;
}
else if (num == 3)
{
count = people[0] + people[1] + people[2];
os << people[0] << " " << people[2] << endl;
os << people[0] << endl;
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
return;
}
smallest = people[0];
secondSmallest = people[1];
if (num %2 ==1)
{
for (int i = num - 1; i != 2; i -= 2)
{
if (smallest + 2 * secondSmallest + people[i] < 2 * smallest + people[i] + people[i - 1])
{
os << smallest << " " << secondSmallest << endl;
count = count + secondSmallest;
os << smallest << endl;
count = count + smallest;
os << people[i - 1] << " " << people[i] << endl;
count = count + people[i];
os << secondSmallest << endl;
count = count + secondSmallest;
}
else
{
os << smallest << " " << people[i] << endl;
count = count + people[i];
os << smallest << endl;
count = count + smallest;
os << smallest << " " << people[i - 1] << endl;
count = count + people[i - 1];
os << smallest << endl;
count = count + smallest;
}
}
count += people[0] + people[1] + people[2];
os << people[0] << " " << people[2] << endl;
os << people[0] << endl;
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
}
else
{
for (int i = num - 1; i != 1; i -= 2)
{
if (smallest + 2 * secondSmallest + people[i] < 2 * smallest + people[i] + people[i - 1])
{
os << smallest << " " << secondSmallest << endl;
count = count + secondSmallest;
os << smallest << endl;
count = count + smallest;
os << people[i - 1] << " " << people[i] << endl;
count = count + people[i];
os << secondSmallest << endl;
count = count + secondSmallest;
}
else
{
os << smallest << " " << people[i] << endl;
count = count + people[i];
os << smallest << endl;
count = count + smallest;
os << smallest << " " << people[i - 1] << endl;
count = count + people[i - 1];
os << smallest << endl;
count = count + smallest;
}
}
count += people[1];
os << people[0] << " " << people[1] << endl;
text = os.str();
cout << count << endl << text;
}
}
Code: Select all
2
8
1
2
3
4
5
6
7
8
7
1
2
3
4
5
6
7