zoukankan      html  css  js  c++  java
  • 洛谷P2239 螺旋矩阵

    传送门

    分析:将整个矩阵看成 “回” 形状的分层结构,然后进行去层处理,使得要求得 ((i,j)) 处于最外层,然后再分情况讨论。最外面的一层共有数: $ 4 * n - 4 $ . 第二层共有数: 4n-4 -8
    假设 $ (i,j) $ 外共有 $ x $ 层,则外层所有的数为: $ ans=4
    nx-4x*x $ 。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <cmath>
    using namespace std ;
    
    inline int read () {
    	int f = 1 , x = 0 ;
    	char ch = getchar () ;
    	while(ch > '9' || ch < '0')  {if(ch == '-')  f = -1 ; ch = getchar () ;} 
    	while(ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + ch - '0' ; ch = getchar () ;}
    	return x * f ;
    }
    
    int n , x , y ;
    int t , ans ;
    
    int main () {
    	n = read () ;
    	x = read () ; y = read () ;
    	t = min(x - 1 , n - x) ;
    	t = min(t , min(y - 1 , n - y) ) ;
    	ans = 4 * n * t - 4 * t * t ;
    	
    	if(x - t == 1)
    		ans += y - t ;
    	else if(x + t == n)
    		ans += 3 * n - 5 * t - 1 - y ;
    	else if(y - t == 1) 
    		ans += 4 * n - 7 * t - 2 - x ;
    	else ans += n - 3 * t + x - 1 ;
    	printf("%d
    " , ans) ;
    	return 0 ;
    }
    
  • 相关阅读:
    [HDOJ3567]Eight II
    [HDOJ3622]Bomb Game
    HTML 5 音频
    下拉菜单
    固定导航及右侧固定广告
    隔行换色
    返回顶部
    HTML 5 视频
    TAB切换
    自我介绍
  • 原文地址:https://www.cnblogs.com/Stephen-F/p/10588108.html
Copyright © 2011-2022 走看看