杭电ACM2037
importjava.util.Scanner;publicclassMain{/***@paramargs*/publicstaticvoidmain(String[]...
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sca = new Scanner(System.in);
int amount;
ch1: while (sca.hasNext()) {
int i =0;
amount = sca.nextInt();
int a[][] = new int[amount][2];
for (int j = 1; j <= amount; j++) {
int b = 0;
while (sca.hasNext()) {
a[i][b] = sca.nextInt();
b++;
if (b == 2) {
break;
}
}
i++;
}
for (int m = 1; m < amount; m++) {
for (int n = 1; n < amount; n++) {
if (a[n - 1][1] > a[n][1]) {
int temp[] = new int[2];
temp = a[n - 1];
a[n - 1] = a[n];
a[n] = temp;
}
}
}
if (sca.nextInt() == 0) {
int count = 1;
int f1 = 0;
for (int mk = 1; mk <= amount - 1; mk++) {
if (a[f1][1] <= a[mk][0]) {
f1 = mk;
count++;
}
}
System.out.println(count);
} else {
continue ch1;
}
}
}
}
按照它的要求我的输入和输出是对的啊 怎么交不上去 它说我wrong answer 展开
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sca = new Scanner(System.in);
int amount;
ch1: while (sca.hasNext()) {
int i =0;
amount = sca.nextInt();
int a[][] = new int[amount][2];
for (int j = 1; j <= amount; j++) {
int b = 0;
while (sca.hasNext()) {
a[i][b] = sca.nextInt();
b++;
if (b == 2) {
break;
}
}
i++;
}
for (int m = 1; m < amount; m++) {
for (int n = 1; n < amount; n++) {
if (a[n - 1][1] > a[n][1]) {
int temp[] = new int[2];
temp = a[n - 1];
a[n - 1] = a[n];
a[n] = temp;
}
}
}
if (sca.nextInt() == 0) {
int count = 1;
int f1 = 0;
for (int mk = 1; mk <= amount - 1; mk++) {
if (a[f1][1] <= a[mk][0]) {
f1 = mk;
count++;
}
}
System.out.println(count);
} else {
continue ch1;
}
}
}
}
按照它的要求我的输入和输出是对的啊 怎么交不上去 它说我wrong answer 展开
2个回答
展开全部
这是我的ac代码,你好好看看吧
#include <stdio.h>
int main()
{
int i,j,k,n,a[101],b[101],l,m[101],p,o,t,d;
while(scanf("%d",&n)!=EOF&&n!=0)
{
for(i=0;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
}
for (i=1; i<n; i++)
{
for (j=0; j<n-i; j++)
{
if (b[j]>b[j+1])
{
k=a[j];l=b[j];
a[j]=a[j+1];b[j]=b[j+1];
a[j+1]=k;b[j+1]=l;
}
}
}
int A[101]={0};
for(i=0;i<n;i++)
{
d=i-1;
int p=0;
while(d>=0)
{
if(a[i]>=b[d])
{
if(p<A[d])
p=A[d];
}
d--;
}
A[i]=p+1;
}
int t=A[0];
for(i=0;i<n;i++)
if(t<A[i])
t=A[i];
printf("%d\n",t);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,j,k,n,a[101],b[101],l,m[101],p,o,t,d;
while(scanf("%d",&n)!=EOF&&n!=0)
{
for(i=0;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
}
for (i=1; i<n; i++)
{
for (j=0; j<n-i; j++)
{
if (b[j]>b[j+1])
{
k=a[j];l=b[j];
a[j]=a[j+1];b[j]=b[j+1];
a[j+1]=k;b[j+1]=l;
}
}
}
int A[101]={0};
for(i=0;i<n;i++)
{
d=i-1;
int p=0;
while(d>=0)
{
if(a[i]>=b[d])
{
if(p<A[d])
p=A[d];
}
d--;
}
A[i]=p+1;
}
int t=A[0];
for(i=0;i<n;i++)
if(t<A[i])
t=A[i];
printf("%d\n",t);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询