Crazy tea party(UVALive 2756)

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

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

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<cmath>
#define pq priority_queue
#define Pi acos(-1.0)
#define MAXX 1000000007
using namespace std;
long long ans[66666];
int go(int x)
{
    return x*(x+1)/2-x;
}
int main()
{
    ans[1]=0;
    int x;
    for(int i=1;i<32768;i++)
    {
        ans[i]=go(i/2)+go(i-i/2);
    }
    int t;
    cin>>t;
    while(t--)
    {
        cin>>x;
        cout<<ans[x]<<endl;
    }
    return 0;
}

Memory: 0 KB Time: 3 MS
Language: C++ 4.8.2 Result: Accepted

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

相关推荐

codeforces 808C——Tea Party(贪心)

C. Tea Party time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp invited all his friends to the tea par

say_c_box的博客 1386

UVALive 2756 Crazy tea party

Question: Description Download as PDF n participants ofcrazy tea partysit around the table. Each minute one pair of neighbors can change their places. Find the minimum time (in minutes) required

peach_yang的博客 617

POJ 1455 Crazy tea party

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

恰同学少年 3564

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

1315 - Crazy tea party Time limit: 3.000 seconds n participants ofcrazy tea partysit around the table. Each minute one pair of neighbors can change their places. Find the minimum time (in minu

SF-_- 的 ACM 博客 3662

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

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

【Codeforces 808 C. Tea Party】+ sort

C. Tea Party time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Polycarp invited all his friends to the tea party to celebrate the holiday. He

楚江枫 737

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

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

Educational Codeforces Round 21 C. Tea Party 贪心

记住,当你觉得很苦很累的时候,你真的在进步。

Na_OH的博客 584

Tea Party

Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 +...

ujn20161222的博客 252

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

【codeforces 808】C.Tea Party(贪心)

目链接:http://codeforces.com/contest/808/problem/C解思路:应该算贪心的思想吧,首先给每个杯子倒茶(a[i]+1)/2毫升,如果茶壶不够,输出-1. 否则,把当前茶壶剩下,倒给其他杯中,从容量最大的开始,直接倒满,如果还有剩余,就给第二大的杯倒满,依次类推,直到茶壶为空。#include <iostream> #include <cstdio>

a342500329a的专栏 708

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
上一篇: Minimum Sum LCM(UVA 10791)
下一篇: Palindrome Numbers(UVALive 2889)
TryMyEdge
博客等级 码龄10年 0粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值