Uva 1315 - Crazy tea party 解题报告(找规律)

uva 1315 - Crazy tea party(数论) 题目链接:uva 1315 - Crazy tea party 题目大意:有n个人顺时针为成一圈,现在相邻的两个人可以互相交换位置,问说最少交换几次可以使得n个人逆时针坐。 解题思路:大概这样的策略师最优的,离1近的从1这边走,离n近的从n这边走。 阅读详情

1315 - Crazy tea party

Time limit: 3.000 seconds

n participants of �crazy tea party� sit around the table. Each minute one pair of neighbors can change their places. Find the minimum time (in minutes) required for all participants to sit in reverse order (so that left neighbors would become right, and right - left).

Input 

The first line is the amount of tests. Each next line contains one integer n (1 <= n <= 32767) - the amount of crazy tea participants.

Output 

For each number n of participants to crazy tea party print on the standard output, on a separate line, the minimum time required for all participants to sit in reverse order.

Sample Input 

3
4
5
6

Sample Output 

2
4
6

    解题报告:将n个参与者的顺序反向,每次只能交换相邻的两个人。

    分析一下,1个人和2个人的时候不用操作,3个人的时候将2,3调换顺序即可。4个人的时候将1,2互换,3,4互换。

    这么来看,每次我们将n个人分成n/2和n-n/2两组,每组都要反向。递推一下可知,反响一段m长度的序列需要m*(m-1)/2次操作。故代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int cal(int n)
{
    return n*(n-1)/2;
}

void work()
{
    int n;
    scanf("%d",&n);

    printf("%d\n", cal(n/2)+cal(n-n/2));
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
        work();
}


Crazy tea party-1455 Crazy tea party Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7229 Accepted: 4914 Description n participants of > sit around the table. Each minute one p 阅读详情

相关推荐

Crazy Tea Party

n participants of "crazy tea party" sit around the table. Each minute one pair of neighbors can change their places. Find the minimum time (in minutes) required for all participants to sit in reverse

当凌绝顶,俯瞰天下 1524

Poj.1455 Crazy tea party 2015/09/22

Crazy tea party Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7233   Accepted: 4915 Description n participants of > sit around the table. Each minute one p

>>--» 唯n1.情缘«--<< 389

POJ-Crazy tea party,很好的一道数学题~~~

Crazy tea party Time Limit:1000MS Memory Limit:10000K Description n participants of << crazy tea party >> sit around the table. Each minute one pair of neighbors...

weixin_30478757的博客 234

uva 1315 Crazy tea party

#include #include #include #include #include #include #include #include #include using namespace std; int main() { int t; cin >> t; while(t--) { int n; cin >>

u010652938的专栏 1637

UVA1315 Crazy Tea Party 题解

UVAOJ 1315 的题解

weixin_67742769的博客 110

POJ 1455 Crazy tea party

POJ 1455 Crazy tea party,环形座位逆序

恰同学少年 3564

Crazy tea party

Crazy tea partyGrade: 10 / Discount: 0.8Time Limit:1000MS Memory Limit:65536K Descriptionn participants of > sit around the table. Each minu

无知的我 1202

1730_Crazy Tea Party(有点难)

n participants of "crazy tea party" sit around the table. Each minute one pair of neighbors can change their places. Find the minimum time (in minutes) required for all participants to sit in reverse

李松雨的专栏 726

zoj 1730 Crazy Tea Party

//水题不水啊! /*类似冒泡程序 如果所有人是线性排列,那我们的工作就是类似冒泡程序做的工作:1,2,3,4,5变为5,4,3,2,1 ,耗时n(n-1)/2 但是出现了环,也就是说1,2,3,4,5变为3,2,1,5,4也可满足条件 我们可以把这个环等分成两个部分 ,每个部分看成是线性的,再把它们花的时间加起来. 当n是偶数时, 每份人数n/2 ,即 2*(n/2 )*(n/2 -1

yzl_rex 1543

Crazy tea partyUVALive 2756)

把N分成差最小的两个部分,即偶数分为N/2和N/2,奇数分为N/2和N/2+1,然后每个部分内部用相邻两个数交换的方法计算所需要的步骤。

TryMyEdge 565

POJ_1455_Crazy tea party_解题思路

题目来源:http://poj.org/problem?id=1455题目意译:有n个人围在桌子前面喝茶,等大家都坐定后,必然有个前后左右顺序,比如:a左边b,b左边c,依次类推,最后一个假设是g,那么他左边必然是a。形成一个圆环。现在有个规则,规定每次只能相邻两个人进行交换位置。请问要经过多少次交换,才能让之前位置交换(b左边a,c左边b,a左边是g)思路:大家都清楚假定是一排的情况下:a ...

weixin_34049948的博客 140

zoj 1730 - Crazy tea party

题目:n个人坐成一圈喝茶,

小白菜又菜 954

合法整数集(51Nod-1315

题目 一个整数集合S是合法的,指S的任意子集subS有Fun(SubS)!=X,其中X是一个固定整数,Fun(A)的定义如下: A为一个整数集合,设A中有n个元素,分别为a0,a1,a2,...,an-1,那么定义:Fun(A)=a0 or a1 or ... or an-1;Fun({}) = 0,即空集的函数值为0.其中,or为或操作。 现在给你一个集合Y与整数X的值,问在集合Y至少删除多...

Alex_McAvoy的博客 674

数论:zoj 1730 || poj 1455 Crazy Tea Party

【转】http://blog.csdn.net/zxy_snow/article/details/5993154   类似冒泡程序如果所有人是线性排列,那我们的工作就是类似冒泡程序做的工作:1,2,3,4,5变为5,4,3,2,1 ,耗时n(n-1)/2但是出现了环,也就是说1,2,3,4,5变为3,2,1,5,4也可满足条件  我们可以把这个环等分成两个部分 ,每个部分看成是线性的,再把它们...

caoruntaogmail的博客 211
上一篇: Uva 11461 - Square Numbers 解题报告(水题)
下一篇: Uva 1319 - Maximum 解题报告(数学)
SF-_-
博客等级 码龄14年 28粉丝 227原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值