WOJ1123-Bishops

探讨了在一个N*N的棋盘上,最多可以放置多少个象而不互相威胁的问题,并给出了简洁的数学公式解答。

KO learned the rules of chess and defeated his father, all his friends, his little brother, and now no one wants to play with him any more. 
And so he plays with himself, that is, he often asks some interesting questions. One day, he moved to this question: ?Given a N*N chessboard, 
how many bishops can be placed on a chessboard without threatening each other at most??. KO was in trouble and you must help the poor boy. 

输入格式

There will be multiple test cases. For each test case, there is a single number n (1 <= n <= 2^32-1) representing the size of the chessboard.

输出格式

For each test case, you must output the maximum bishops that can be placed without threatening each other.

样例输入

2
3

样例输出

2
4

ans=2*n-2,证明比较简单。。N=1的时候要特判

#include<stdio.h>
long long n;
int main(){
    while(scanf("%d",&n)!=EOF){
    	if(n==1)
    	printf("1\n");
    	else
    	printf("%lld\n",2*n-2);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值