Ensemble @ 2018-02-26 20:11:04
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n, p[305], yw[205], sx[305], yy[305], a[305];
void change(int i){
swap(a[i], a[i+1]);
swap(yw[i], yw[i+1]);
swap(p[i], p[i+1]);
}
void Bsort(int a[], int n){//排序
for(int i=1; i<=n; i++){
bool flag=true;
for(int j=1; j<=n-1; j++)
if(a[j]<a[j+1]) change(j), flag=false;
if(flag) return;
}
}
void check(){//调换等分顺序
for(int i=1; i<n; i++)
if(a[i]==a[i+1]){
if(yw[i]<yw[i+1]) change(i);
else if(yw[i]==yw[i+1])
if(p[i]>p[i+1]) change(i);
}
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
cin>>yw[i]>>sx[i]>>yy[i];
p[i]=i;
a[i]=yw[i]+sx[i]+yy[i];
}
Bsort(a, n);
check();
for(int i=1; i<=5; i++) cout<<p[i]<<' '<<a[i]<<endl;
return 0;
}
//++
by YWY_wys @ 2018-02-26 20:32:18
不知道你们题库的数据中有没有n<5的数据
by YWY_wys @ 2018-02-26 20:34:30
@孤独旅者。 有的话就过不了啦
by Ensemble @ 2018-02-26 20:51:32
@YWY_wys 然而 并没有
by YWY_wys @ 2018-02-26 21:26:43
@孤独旅者。 5 91 90 89 89 90 91 90 90 90 92 88 90 90 92 88 这样的数据你过不去
by Ensemble @ 2018-02-27 08:01:04
@YWY_wys U r right, thank u very much!
by Ensemble @ 2018-02-27 08:09:23
@YWY_wys 但是我改了这点后还是80分
by YWY_wys @ 2018-02-27 08:15:47
@孤独旅者。 能把改后的code私信我吗?
by Ensemble @ 2018-02-27 08:18:58
@YWY_wys 我们OJ的input数据没给完,给了几行, 然后就是省略号了,但给了完整的output和result
input:
220
79 57 69
95 33 85
65 74 61
82 39 48
33 64 57
73 39 69
34 56 82
96 43 52
81 53 71
65 74 58
96 59 ...
- output:
53 280
93 280
136 275
26 273
140 271
result:
wrong answer 1st lines differ - expected: '13 280', found: '53 280'
input:
270
79 51 81
97 83 71
95 51 30
95 35 49
43 34 68
68 58 30
93 40 98
32 34 67
59 57 54
33 44 81
52 36 ...
output:
50 289
173 284
59 277
93 277
84 273
result:
wrong answer 1st lines differ - expected: '150 289', found: '50 289'
by Ensemble @ 2018-02-27 08:21:05
@YWY_wys ```cpp
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n, p[305], yw[205], sx[305], yy[305], a[305];
void change(int i){
swap(a[i], a[i+1]);
swap(yw[i], yw[i+1]);
swap(p[i], p[i+1]);
}
void Bsort(int a[], int n){//排序
for(int i=1; i<=n; i++){
bool flag=true;
for(int j=1; j<=n-1; j++)
if(a[j]<a[j+1]) change(j), flag=false;
if(flag) return;
}
}
void check(){//调换等分顺序
for(int i=1; i<n; i++)
if(a[i]==a[i+1]){
if(yw[i]<yw[i+1]) {change(i); check();}
else if(yw[i]==yw[i+1])
if(p[i]>p[i+1]) {change(i); check();}
}
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
cin>>yw[i]>>sx[i]>>yy[i];
p[i]=i;
a[i]=yw[i]+sx[i]+yy[i];
}
Bsort(a, n);
check();
for(int i=1; i<=5; i++) cout<<p[i]<<' '<<a[i]<<endl;
return 0;
}
by YWY_wys @ 2018-02-27 09:03:55
@孤独旅者。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n, p[305], yw[205], sx[305], yy[305], a[305];
void change(int i){
swap(a[i], a[i+1]);
swap(yw[i], yw[i+1]);
swap(p[i], p[i+1]);
}
void Bsort(int a[], int n){//排序
for(int i=1; i<=n; i++){
bool flag=true;
for(int j=1; j<=n-1; j++) {
if(a[j]<a[j+1]) change(j),flag=false;
else if(a[j]==a[j+1]){
if(yw[j]<yw[j+1]) change(j),flag=false;
else if(yw[j]==yw[j+1])
if(p[i]>p[j+1]) change(j),flag=false;
}
}
if(flag) return;
}
}
/*void check(){//调换等分顺序
for(int i=1; i<n; i++)
if(a[i]==a[i+1]){
if(yw[i]<yw[i+1]) change(i);
else if(yw[i]==yw[i+1])
if(p[i]>p[i+1]) change(i);
}
}*/
int main(){
cin>>n;
for(int i=1; i<=n; i++){
cin>>yw[i]>>sx[i]>>yy[i];
p[i]=i;
a[i]=yw[i]+sx[i]+yy[i];
}
Bsort(a, n);
//check();
for(int i=1; i<=5; i++) cout<<p[i]<<' '<<a[i]<<endl;
return 0;
}
如果这个都过不了的话我就没办法了