| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
直接上代码吧!哇咔咔。/***********************************************************************
Copyright (c) 2015,wangzp
All rights no reserved.
Name: 《Crazy tea party》In PEKING UNIVERSITY ACM
ID: PROBLEM 1455
问题简述: N个人围成一圈,找出最快反着做需要调换座位的次数。
Date: SEP 09, 2015
***********************************************************************/
#include <stdio.h>
/*偶数个人*/
int fun_even(int n)
{
return n/2*(n/2 - 1);
}
/*奇数个人*/
int fun_odd(int n)
{
return (n/2)*(n/2 -1)/2 + (n/2 +1)*(n/2)/2;
}
int main(void)
{
int m,a,result;
scanf("%d",&m);
while(m--)
{
scanf("%d",&a);
if (a%2 == 0)
{
result = fun_even(a);
printf("%d\n",result);
}
else
{
result = fun_odd(a);
printf("%d\n",result);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator