1 条题解
-
0
C++ :
#include<stdio.h> void shuru( int [] ,int [] ,int , int * ); void shuchu( int [] ,int , int ); int main(void) { int n , bj = 0 ; scanf("%d" , &n ); int s1[8] ,s2[8] ; shuru( s1 , s2 , n , &bj); shuchu( s1 , n , bj ); return 0 ; } void shuchu( int s1[] ,int n, int t) { if( t != 0 ) { int tag = 0; int flg = 0; int i , j ; for( i = 0 ; i < n ;i ++ ) { int sum = 0 ; if( s1[i] != 0 ) { for( j = 0 ;j < n ; j ++ ) { if( i == j ) { continue; } if(s1[i] == s1[j]) { sum ++ ; } if(s1[j] == s1[i] + 1 ) { sum = 0 ; } } if(sum >= s1[i] && flg <= s1[i]) { printf("%d", i + 1 ); flg ++ ; } } else { for( j = 0 ; j < n ; j ++ ) { if(s1[j] == 1 ) { tag ++ ; } } if(tag == 0 ) { printf("%d", i+1); tag = -1 ; } } } if(flg == 0 && tag != -1 ) { printf("NoSolution"); } } else { putchar('0'); } } void shuru( int s1[] ,int s2[] ,int n , int * bj ) { int i ; for( i = 0 ; i < n ; i ++ ) { scanf("%d%d" , &s1[i] , &s2[i]); if( s1[i] == 0 ) { ++ * bj ; } } }
Java :
import java.util.Scanner; public class Main { static int count=0; public static void main(String[] args) { Scanner input=new Scanner(System.in); int n=input.nextInt(); int a[]=new int[n]; int b[]=new int[n]; int t=0; for(int i=0;i<n;i++) { a[i]=input.nextInt(); b[i]=input.nextInt(); if(a[i]==0) t++; } input.close(); if(t!=0) { int tag=0; int flg=0; for(int i=0;i<n;i++) { int cnt=0; if(a[i]!=0) { for(int j=0;j<n;j++) { if(i==j) continue; if(a[i]==a[j]) cnt++; if(a[j]==a[i]+1) cnt=0; } if(cnt>=a[i] && flg<=a[i]) { System.out.print(i+1); flg++; } } else { for(int j=0;j<n;j++) if(a[j]==1) tag++; if(tag==0) { System.out.println(i+1); tag=-1; } } } if(flg==0 && tag!=-1) System.out.println("NoSolution"); } else System.out.println(0); } }
- 1
信息
- ID
- 2735
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者