zoukankan      html  css  js  c++  java
  • CF1004D Sonya and Matrix

    不要想当然。

    考虑到我们一定有存在个数为(4)的倍数的数。
    否则第一个不是的数即为(x)
    那么我们设(b)为所有的数的最大值。
    那么显然有(|n - x| + |m - y| = b)
    那么有(y = n + m - x - b)
    所以我们只要暴力枚举(t)的约数,然后暴力判断。

    #include<iostream>
    #include<cstdio>
    #define ll long long 
    #define N 1000010
    
    ll cnt[N << 1],ct[N << 1];
    
    ll a,b,x,y;
    ll t;
    
    ll abs(ll x){return x > 0 ? x : -x;}
    
    int main(){
    	scanf("%lld",&t);
    	for(int i = 1;i <= t;++i){
    		ll x;
    		scanf("%lld",&x);
    		cnt[x] ++ ;
    		b = std::max(x,b);
    	}
    	for(int i = 1;i <= t;++i){
    		if(cnt[i] < i * 4){
    			x = i;
    			break;
    		}
    	}
    	for(int i = 1;i <= t;++i){
    		if(t % i == 0){
    			int n,m;
    			n = i,m = t / i;
    			y = n + m - x - b;
    			if(abs(n - x) + abs(m - y) == b){
    				for(int i = 1;i <= t;++i)
    				ct[i] = 0;
    				for(int j = 1;j <= n;++j)
    				for(int k = 1;k <= m;++k)
    				ct[abs(j - x) + abs(k - y)] ++ ;
    				bool k = 1;
    				for(int i = 1;i <= t;++i)
    				if(cnt[i] != ct[i])
    				{
    					k = 0;
    					break;
    				}
    				if(k){
    					std::cout<<n<<" "<<m<<std::endl<<x<<" "<<y<<std::endl;
    					return 0;
    				}
    			}
    		}
    	}
    	puts("-1");
    	return 0;
    }
    
  • 相关阅读:
    修改css样式+jq中的效果+属性操作+元素操作
    案例1:点击菜单显示相应的图片
    jq容易混淆点
    jQuery中的选择器
    JQ基本
    arguments的使用
    函数方法
    forEach遍历
    数组中常用的方法
    数组 Array
  • 原文地址:https://www.cnblogs.com/dixiao/p/15231256.html
Copyright © 2011-2022 走看看