跪求杭电acm1052找错能想到的数据我都带出来了wa
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>intcmp(constvoid...
# include <stdio.h>
# include <string.h>
# include <math.h>
# include <stdlib.h>
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}
int main(int argc, char *argv[])
{
int n,a,b,c,k,sum=0;
while(scanf("%d",&n)!=EOF&&n){
int sh1[1000],sh2[1000];
for(a=0;a<n;a++)
scanf("%d",&sh1[a]);
for(a=0;a<n;a++)
scanf("%d",&sh2[a]);
qsort(sh1,n,sizeof(int),cmp);
qsort(sh2,n,sizeof(int),cmp);
for(sum=0,k=1,a=0,b=0;a<n;a++){
if(sh1[a]>sh2[b])
sum+=200,b++;
else if(sh1[a]==sh2[b]){
if((a+1)>=n||(b+1)>=n)
b++;
else {
if(sh1[a+1]>sh2[b+1])
b++;
else if(sh1[a+1]<sh2[b+1]&&sh1[a+1]>sh2[b])
b++;
else {
if(sh1[a+1]==sh2[b+1]&&sh1[a+1]>sh2[b])b=b++,k++;
else
b++;
}
}
}
}
sum-=(a-b)*200;
if(k>2)
sum+=200*(k-2);
printf("%d\n",sum);
}
return 0;
} 展开
# include <string.h>
# include <math.h>
# include <stdlib.h>
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}
int main(int argc, char *argv[])
{
int n,a,b,c,k,sum=0;
while(scanf("%d",&n)!=EOF&&n){
int sh1[1000],sh2[1000];
for(a=0;a<n;a++)
scanf("%d",&sh1[a]);
for(a=0;a<n;a++)
scanf("%d",&sh2[a]);
qsort(sh1,n,sizeof(int),cmp);
qsort(sh2,n,sizeof(int),cmp);
for(sum=0,k=1,a=0,b=0;a<n;a++){
if(sh1[a]>sh2[b])
sum+=200,b++;
else if(sh1[a]==sh2[b]){
if((a+1)>=n||(b+1)>=n)
b++;
else {
if(sh1[a+1]>sh2[b+1])
b++;
else if(sh1[a+1]<sh2[b+1]&&sh1[a+1]>sh2[b])
b++;
else {
if(sh1[a+1]==sh2[b+1]&&sh1[a+1]>sh2[b])b=b++,k++;
else
b++;
}
}
}
}
sum-=(a-b)*200;
if(k>2)
sum+=200*(k-2);
printf("%d\n",sum);
}
return 0;
} 展开
1个回答
展开全部
你的贪心方法不对,应该是这样
当田忌最慢的马比齐王最慢的马快,赢一场先
2.当田忌最慢的马比齐王最慢的马慢,和齐王最快的马比,输一场
3. 如果 = = 则
one.当田忌最快的马比齐王最快的马快时,赢一场先。
two.当田忌最快的马比齐王最快的马慢时,拿最慢的马和齐王最快的马比,输一场。
three.当田忌最快的马和齐王最快的马相等时,拿最慢的马来和齐王最快的马比.,输一场
# include <stdio.h>
# include <string.h>
# include <math.h>
# include <stdlib.h>
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}
int main(int argc, char *argv[])
{
int n,a,b,c,k,sum=0;
while(scanf("%d",&n)!=EOF&&n){
int sh1[1000],sh2[1000];
for(a=0;a<n;a++)
scanf("%d",&sh1[a]);
for(a=0;a<n;a++)
scanf("%d",&sh2[a]);
qsort(sh1,n,sizeof(int),cmp);
qsort(sh2,n,sizeof(int),cmp);
for(sum=0,k=1,a=0,b=0;a<n;a++){
if(sh1[a]>sh2[b])
sum+=200,b++;
else if(sh1[a]==sh2[b]){
if((a+1)>=n||(b+1)>=n)//这儿就有问题,当最慢的相等时,比较最大的,而你是继续比较最慢的,
b++;
else {
if(sh1[a+1]>sh2[b+1])
b++;
else if(sh1[a+1]<sh2[b+1]&&sh1[a+1]>sh2[b])
b++;
else {
if(sh1[a+1]==sh2[b+1]&&sh1[a+1]>sh2[b])b=b++,k++;
else
b++;
}
}
}
}
只要遵循上面的方法,就能过了,欢迎继续交流
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询