Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 请问大神，我这样写为什么总是WA，，用大神给的数据都测过了，没有发现问题，，求助，，感觉自己好水啊，这么简单都WA了那么多次。。

Posted by Nsamper at 2016-12-29 03:19:04 on Problem 1230
```//
//  main.cpp
//  ACMUsing
//
//  Created by SupingLi on 16/12/28.
//

#include <cstdio>
#include <algorithm>

using namespace std;
int t,n,k;

struct w{
int l,r;
int inUse;
}wall[100];

//1230
//先对输入排序，按照x从小到大排，x相同则按、、、、、y从大到小排
//遍历点，从左到右边，超过最大数，则找到最大右边的墙，使他失效
//数据都试过了，没有问题，可是就是WA，心好累。。

int compare(w a, w b) {
int x = a.l <= b.l;
int y = a.r >= b.r;
if (a.l == b.l)
return y;
else
return x;
}

int work() {
int i, j, columnCount = 0, ans = 0;
struct w pre = wall[0],maxRWall;
int maxR=0;
if (k == 0)
return n;
sort(wall,wall+n,compare);
for (i = 0; i < n; i ++) {
if (wall[i].inUse == 0) {
continue;
}
pre = wall[i];
maxR=-1;
maxRWall=pre;
columnCount = 0;
for (j = 0; j < n; j ++) {
if (wall[j].inUse == 0) {
continue;
}
if (wall[j].l <= pre.r && wall[j].r >= pre.l) {
if (columnCount < k) {
columnCount++;
if (wall[i].r >= wall[j].r)
pre = wall[j];
} else{
maxR=i;
if (maxRWall.r < wall[j].r) {
maxRWall = wall[j];
maxR = j;
}
}
}
}
//找到有超过最大墙数的情况
if(maxR != -1) {
wall[maxR].inUse = 0;
ans ++;
}
}
return ans;
}

int main()
{
int i;
int a,b,temp;
scanf("%d",&t);
while (t--) {
scanf("%d%d",&n,&k);
for (i = 0; i < n; i ++) {
scanf("%d%d%d%d",&wall[i].l,&a,&wall[i].r,&b);
if (wall[i].l > wall[i].r) {
temp = wall[i].l;
wall[i].l = wall[i].r;
wall[i].r = temp;
}
wall[i].inUse = 1;
}
printf("%d\n",work());
}
return 0;
}```

Followed by: