Last active
December 6, 2016 08:58
-
-
Save taichunmin/2c982e51f7f9c3eac8e8bce7d2e9b0b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 4 5 | |
1 3 1 | |
3 2 2 | |
2 3 5 | |
3 4 4 | |
1 6 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <deque> | |
#include <algorithm> | |
#include <cstdio> | |
using namespace std; | |
struct Node { | |
int h, id; | |
}; | |
bool cmpNode(Node na, Node nb) | |
{ | |
return na.h > nb.h; // 由大到小 | |
} | |
int main() | |
{ | |
int L, n, m, a, b, c, ans[1000]; | |
deque<Node> line[1000]; | |
while(cin>>L>>n>>m) { | |
for(int i=0; i<n; i++) | |
line[i].clear(); | |
for(int i=0; i<m; i++) { | |
cin>>a>>b>>c; | |
Node na {b, i}, nb {c, i}; | |
line[a-1].push_back(na); | |
line[a].push_back(nb); | |
} | |
for(int i=0; i<n; i++) { | |
sort(line[i].begin(), line[i].end(), cmpNode); | |
ans[i] = i; | |
// for(Node tmp: line[i]) | |
// printf("{%d, %d} ", tmp.h, tmp.id); | |
// puts(""); | |
} | |
while(m>0) { | |
Node na, nb; | |
for(int i=0; i<n-1; i++) | |
if(!line[i].empty() && !line[i+1].empty() && (*line[i].begin()).id == (*line[i+1].begin()).id) { | |
swap(ans[i], ans[i+1]); | |
line[i].pop_front(); | |
line[i+1].pop_front(); | |
m--; | |
} | |
} | |
cout<<"ans: "; | |
for(int i=0; i<n; i++) | |
cout<<ans[i]+1<<' '; | |
cout<<endl; | |
} | |
} | |
/* | |
https://paiza.jp/challenges/20/page/problem | |
7 4 5 | |
1 3 1 | |
3 2 2 | |
2 3 5 | |
3 4 4 | |
1 6 6 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment