1 条题解

  • 0
    @ 2024-12-24 9:59:19

    C :

    #include<stdio.h>
    main()
    {
    	int zheng[120],fan[120],n,unsame,sumzheng,sumfan;
    	while(scanf("%d",&n)!=EOF)
    	{
    		unsame=0;
    		sumzheng=0;
    		sumfan=0;
    		while(n--)
    		{
    			scanf("%d %d",&zheng[n],&fan[n]);
    			sumzheng+=zheng[n];
    			sumfan+=fan[n];
    			if(zheng[n]%2!=fan[n]%2)
    			unsame++;
    		}
    		if(sumzheng%2==1&&sumfan%2==1)
    		{
    			if(unsame!=0)
    			puts("1");
    			else
    			puts("-1");
    			continue;
    		}
    		if(sumzheng%2!=sumfan%2)
    		{
    			puts("-1");
    			continue;
    		}
    		if(sumzheng%2==0&&sumfan%2==0)
    		{
    			puts("0");
    			continue;
    		}
    	}
    }
    

    C++ :

    #include<stdio.h>
    #include<string.h>
    
    int depth[6];
    int sum_Upper, sum_Lower;
    int m;
    
    int main(){
        int i, j, k;
        int a, b;
        //freopen("1.in", "r", stdin);
        //freopen("1.out", "w", stdout);
        while(scanf("%d", &m) != EOF){
            sum_Lower = sum_Upper = 0;
            memset(depth, 0, sizeof(depth));
            for(i = 0; i < m; i++){
                scanf("%d%d", &a, &b);
                sum_Upper += a;
                sum_Lower += b;
                int s = a - b < 0 ? b - a : a - b;
                depth[s]++;
            }
            if((sum_Upper + sum_Lower ) % 2){
                printf("-1\n");
                continue;
            }
            bool q = sum_Upper % 2 ? false : true;
            bool p = sum_Lower % 2 ? false : true;
            if(q && p){
                printf("0\n");
                continue;
            }
            if(depth[1] || depth[3] || depth[5]){
                printf("1\n");
            }
            else{
                printf("-1\n");
            } 
        }
        return 0;
    }
    
    • 1

    信息

    ID
    1413
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者