zoukankan      html  css  js  c++  java
  • UVA11538 Chess Queen

    题意

    给一个(n imes m)的棋盘,输出有多少种方法放置两个互相攻击的皇后。

    (n,m leq 10^6)

    分析

    参照刘汝佳的题解。

    横、竖、斜三种情况互不相干,加法原理统计。

    横竖都好计算,斜着需要推一推。

    然后注意溢出问题。

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<set>
    #include<map>
    #include<queue>
    #include<stack>
    #include<algorithm>
    #include<bitset>
    #include<cassert>
    #include<ctime>
    #include<cstring>
    #define rg register
    #define il inline
    #define co const
    template<class T>il T read()
    {
    	rg T data=0;
    	rg int w=1;
    	rg char ch=getchar();
    	while(!isdigit(ch))
    	{
    		if(ch=='-')
    			w=-1;
    		ch=getchar();
    	}
    	while(isdigit(ch))
    	{
    		data=data*10+ch-'0';
    		ch=getchar();
    	}
    	return data*w;
    }
    template<class T>T read(T&x)
    {
    	return x=read<T>();
    }
    using namespace std;
    typedef unsigned long long ull;
    
    int main()
    {
    //	freopen(".in","r",stdin);
    //	freopen(".out","w",stdout);
    	ull n,m;
    	while(read(n)|read(m))
    	{
    		if(n>m)
    			swap(n,m);
    		printf("%llu
    ",n*m*(m+n-2)+2*n*(n-1)*(3*m-n-1)/3);
    	}
    	return 0;
    }
    
  • 相关阅读:
    Python爬虫学习01
    Python学习Day02
    JavaScript学习笔记01
    Python学习Day01
    MarkDown实例代码
    MarkDwon的使用方法
    (转)探究requestDisallowInterceptTouchEvent失效的原因
    JNI字符串转字节数组指针方法
    justfun
    dsad
  • 原文地址:https://www.cnblogs.com/autoint/p/10025534.html
Copyright © 2011-2022 走看看