杭电acm1050题,一直wa求大牛们帮忙!!!
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1050#include<stdio.h>#include<iostream...
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=1050#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
struct room
{
int s;
int t;
}rooms[210];
int cmp( const void *a , const void *b )
{
struct room *c =(room *)a;
struct room *d =(room *)b;
if(c->s!=d->s)
return c->s-d->s;
else
return c->t-d->t;
}
int main()
{
int i,j,n,sum,m,ri,repeat,temp;
cin>>repeat;
for(ri=0;ri<repeat;ri++)
{
sum=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>rooms[i].s>>rooms[i].t;
if(rooms[i].s>rooms[i].t)
{
temp=rooms[i].s;
rooms[i].s=rooms[i].t;
rooms[i].t=temp;
}
}
qsort(rooms,n,sizeof(rooms[0]),cmp);
j=0;
for(i=1;i<n;i++)
{
if((rooms[j].t+1==rooms[i].s&&rooms[j].t%2!=0)||(rooms[j].t>rooms[i].s))
{
sum++;
j=i;
}
}
cout<<(sum+1)*10<<endl;
}
return 0;
} 展开
http://acm.hdu.edu.cn/showproblem.php?pid=1050#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
struct room
{
int s;
int t;
}rooms[210];
int cmp( const void *a , const void *b )
{
struct room *c =(room *)a;
struct room *d =(room *)b;
if(c->s!=d->s)
return c->s-d->s;
else
return c->t-d->t;
}
int main()
{
int i,j,n,sum,m,ri,repeat,temp;
cin>>repeat;
for(ri=0;ri<repeat;ri++)
{
sum=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>rooms[i].s>>rooms[i].t;
if(rooms[i].s>rooms[i].t)
{
temp=rooms[i].s;
rooms[i].s=rooms[i].t;
rooms[i].t=temp;
}
}
qsort(rooms,n,sizeof(rooms[0]),cmp);
j=0;
for(i=1;i<n;i++)
{
if((rooms[j].t+1==rooms[i].s&&rooms[j].t%2!=0)||(rooms[j].t>rooms[i].s))
{
sum++;
j=i;
}
}
cout<<(sum+1)*10<<endl;
}
return 0;
} 展开
展开全部
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
struct room
{
int s;
int t;
bool selected;
}rooms[210];
int cmp( const void *a , const void *b )
{
struct room *c =(room *)a;
struct room *d =(room *)b;
if(c->s!=d->s)
return c->s-d->s;
else
return c->t-d->t;
}
int main()
{
int i,j,n,sum,m,ri,repeat,temp;
cin>>repeat;
for(ri=0;ri<repeat;ri++)
{
sum=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>rooms[i].s>>rooms[i].t;
rooms[i].selected = false;
if(rooms[i].s>rooms[i].t)
{
temp=rooms[i].s;
rooms[i].s=rooms[i].t;
rooms[i].t=temp;
}
}
qsort(rooms,n,sizeof(rooms[0]),cmp);
while(1)
{
j=0;
while(j<n && rooms[j].selected) j++;
if(j==n) break;
sum++;
rooms[j].selected = true;
for(i=j+1;i<n;i++)
{
if(rooms[i].selected) continue;
if(!((rooms[j].t+1==rooms[i].s&&rooms[j].t%2!=0)||(rooms[j].t>=rooms[i].s)))
{
rooms[i].selected = true;
j=i;
}
}
}
cout<<sum*10<<endl;
}
return 0;
}
#include<iostream>
#include<stdlib.h>
using namespace std;
struct room
{
int s;
int t;
bool selected;
}rooms[210];
int cmp( const void *a , const void *b )
{
struct room *c =(room *)a;
struct room *d =(room *)b;
if(c->s!=d->s)
return c->s-d->s;
else
return c->t-d->t;
}
int main()
{
int i,j,n,sum,m,ri,repeat,temp;
cin>>repeat;
for(ri=0;ri<repeat;ri++)
{
sum=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>rooms[i].s>>rooms[i].t;
rooms[i].selected = false;
if(rooms[i].s>rooms[i].t)
{
temp=rooms[i].s;
rooms[i].s=rooms[i].t;
rooms[i].t=temp;
}
}
qsort(rooms,n,sizeof(rooms[0]),cmp);
while(1)
{
j=0;
while(j<n && rooms[j].selected) j++;
if(j==n) break;
sum++;
rooms[j].selected = true;
for(i=j+1;i<n;i++)
{
if(rooms[i].selected) continue;
if(!((rooms[j].t+1==rooms[i].s&&rooms[j].t%2!=0)||(rooms[j].t>=rooms[i].s)))
{
rooms[i].selected = true;
j=i;
}
}
}
cout<<sum*10<<endl;
}
return 0;
}
追问
额,谢谢大神,但还是想不通自己那样做为什么是错的?跪求指导
追答
是扫一遍是不行的
比如说你可以试一下
4
10 20
20 30
30 40
40 50
华芯测试
2024-09-01 广告
2024-09-01 广告
电学测试台是深圳市华芯测试科技有限公司的核心设备之一,它集成了高精度测量仪器与自动化控制系统,专为半导体芯片、电子元件及模块的电性能检测而设计。该测试台能够迅速、准确地完成电压、电流、电阻、电容及频率等关键参数的测试,确保产品质量符合行业标...
点击进入详情页
本回答由华芯测试提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询