zoukankan      html  css  js  c++  java
  • The Pilots Brothers' refrigerator

    POJ

    给定一个(4*4)的字符矩阵,只有'-'和'+'两个字符,求使的所有'+'变成'-'的最小步骤,并输出任意一种方案.

    对于任何一个格子,变动奇数次才是有效的变动,偶数次变动是无效的.我们直接开一个4*4的数组,初始化全为0,然后对于每个'+'的格子,我们令它所在的行和列上的格子全部+1,最后最小步数就是变动奇数次格子的数量,方案直接就是奇数次的格子.

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<map>
    #define ll long long
    using namespace std;
    inline int read(){
        int x=0,o=1;char ch=getchar();
        while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
        if(ch=='-')o=-1,ch=getchar();
        while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
        return x*o;
    }
    int a[5][5];
    int main(){
    	for(int i=1;i<=4;++i)
    		for(int j=1;j<=4;++j){
    			char ch;cin>>ch;
    			if(ch=='+'){
    				for(int k=1;k<=4;++k)
    					a[i][k]++,
    					a[k][j]++;
    				a[i][j]--;
    			}
    		}
    	int ans=0;
    	for(int i=1;i<=4;++i) 
    		for(int j=1;j<=4;++j) 
    			if(a[i][j]&1)++ans;
    	printf("%d
    ",ans);
    	for(int i=1;i<=4;++i) 
    		for(int j=1;j<=4;++j)
    			if(a[i][j]&1)printf("%d %d
    ",i,j);
    	return 0;	
    }
    
    
    
  • 相关阅读:
    逆元(费马小定理求法)
    CodeForces
    lower_bound and upper_bound
    HDU 4825 Xor Sum
    1030: [JSOI2007]文本生成器
    1070: [SCOI2007]修车
    agc 027 B
    P2664 树上游戏
    CF 314 E. Sereja and Squares
    4237: 稻草人
  • 原文地址:https://www.cnblogs.com/PPXppx/p/11256718.html
Copyright © 2011-2022 走看看