链接:https://ac.nowcoder.com/acm/contest/1077/L

题目描述

Bessie and the herd, N (1 <= N <= 2,200) conveniently numbered 1..N cows in all, have gone to a dance where plenty of bulls are available as dancing partners. This dance is known as the "odd cow out" dance because of the way cows are chosen to dance with bulls.
The cows are lined up in numerical order and the 'middle' point is chosen. It either divides the line of cows exactly in half or it is chosen so that the first set of cows has just one more cow in it than the second set. If exactly two cows are in the set, they are chosen to dance with bulls. If one cow is in the set, she is sent home with a consolation prize of a beautiful rose.
If the set has more than two cows in it, the process is repeated perhaps again and again until sets with just one or two cows emerge.
The two cow ID numbers are multiplied together and added to a global sum.
Given the number of cows at the dance, compute the global sum after all the eligible cows are chosen.

Consider a dance with 11 cows numbered 1..11. Here is the sequence of dividing them:
1 2 3 4 5 6 | 7 8 9 10 11 1 2 3 | 4 5 6 1 2 | 3
1 2 => 1*2=2 added to sum -> sum=2
3 => sent home with rose 4 5 | 6
4 5 => 4*5=20 added to sum -> sum=22
6 => sent home with rose 7 8 9 | 10 11 7 8 | 9
7 8 => 7*8=56 added to sum -> sum=78
9 => sent home with rose
10 11 => 10*11=110 added to sum -> sum=188 So the sum for this dance would be 188.

输入描述:

* Line 1: A single integer: N

输出描述:

* Line 1: A single integer that is the sum computed as prescribed.

示例1

输入


输出


简单二分,直接粘代码

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const double PI=acos(-);
const int maxn=;
using namespace std;
//ios::sync_with_stdio(false);
// cin.tie(NULL); int n,ans; void solve(int l,int r)
{
if(l==r)
return ;
if(l+==r)
{
ans+=l*r;
return ;
}
int mid=(l+r)>>;
solve(l,mid);
solve(mid+,r);
return ;
} int main()
{
scanf("%d",&n);
solve(,n);
printf("%d\n",ans);
return ;
}
 
 
 

TOJ-3474 The Big Dance(递归二分)的更多相关文章

  1. Python练习-递归二分算法

    # 编辑者:闫龙 #递归,二分算法演示 l = [i for i in range(1,100)]#定义一个列表l,并追加1-99的所有数字 def FindNum(num,l):#定义函数FindN ...

  2. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  3. python-Day4-迭代器-yield异步处理--装饰器--斐波那契--递归--二分算法--二维数组旋转90度--正则表达式

    本节大纲 迭代器&生成器 装饰器  基本装饰器 多参数装饰器 递归 算法基础:二分查找.二维数组转换 正则表达式 常用模块学习 作业:计算器开发 实现加减乘除及拓号优先级解析 用户输入 1 - ...

  4. Python递归 — — 二分查找、斐波那契数列、三级菜单

    一.二分查找 二分查找也称之为折半查找,二分查找要求线性表(存储结构)必须采用顺序存储结构,而且表中元素顺序排列. 二分查找: 1.首先,将表中间位置的元素与被查找元素比较,如果两者相等,查找结束,否 ...

  5. 巨蟒python全栈开发-第14天 内置函数2 递归 二分查找

    一.今日内容总览 1.内置函数补充 repr() 显示出字符串的官方表示形式 chr() arscii码中的字,转换成位置 ord() arscii码中的位置,转换成字2.递归 自己调用自己 两个口: ...

  6. BZOJ 1305 CQOI2009 dance跳舞 二分答案+最大流

    题目大意:给定n个男生和n个女生,一些互相喜欢而一些不.举行几次舞会,每次舞会要配成n对.不能有同样的组合出现.每一个人仅仅能与不喜欢的人跳k次舞,求最多举行几次舞会 将一个人拆成两个点.点1向点2连 ...

  7. BZOJ 1305 dance跳舞 二分+最大流

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1305 题目大意: 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成 ...

  8. 【Luogu】【关卡2-12】递推与递归二分(2017年10月)

    任务说明:递推,层层递进,由基础推向顶层.二分不仅可以用来查找数据,还可以确定最合适的值. P1192 台阶问题 有N级的台阶,你一开始在底部,每次可以向上迈最多K级台阶(最少1级),问到达第N级台阶 ...

  9. toj 4353 Estimation(树状数组+二分查找)

    Estimation 时间限制(普通/Java):5000MS/15000MS     运行内存限制:65536KByte总提交: 6            测试通过: 1 描述 “There are ...

随机推荐

  1. StringBuffer类、StringBuilder类详解

    StringBuffer是一个字符串缓冲区,是一个容器,而且长度可变,可以直接操作多个数据类型, 最终会通过toString()方法变成字符串. 容器的功能有: 1.存储 public StringB ...

  2. C#高级编程(第9版) 第10章 集合 笔记

    话说 虽然敲过好多代码, 但除了C++,一直没正眼瞧过其它语言.(没办法 谁叫C++既有oop又能自由控制内存呢) 今天 看公司老项目的src,c#的,linq+Dictionary的用法有感.所以找 ...

  3. python刷LeetCode:9. 回文数

    难度等级:简单 题目描述: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121输出: true示例 2: 输入: -121输出: fa ...

  4. 51nod1007:正整数分组 DP

    1007 正整数分组 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 ...

  5. 洛谷 P2658 汽车拉力比赛

    题目传送门 解题思路: 二分答案,然后bfs验证,如果从一个路标可以达到其它所有路标,则答案可行.知道找到最佳答案. AC代码: #include<iostream> #include&l ...

  6. 对python里的装饰器

    内裤可以用来遮羞,但是到了冬天它没法为我们防风御寒,聪明的人们发明了长裤,有了长裤后宝宝再也不冷了,装饰器就像我们这里说的长裤,在不影响内裤作用的前提下,给我们的身子提供了保暖的功效. 再回到我们的主 ...

  7. GitHub练习——如何将本地已有项目添加到github

    刚开始开始接触,搞点简单的,看看是怎么把项目传上去,总结一下,大概是这些步骤: 创建本地仓库 将本地仓库变成git可管理的仓库:git init 把项目文件添加到缓存区:项目文件添加到已有的仓库,然后 ...

  8. linux中nc命令

    语法 nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o<输出文件>][-p<通信端口>][-s ...

  9. 直击JDD | 徐雷:智能化零售,以技术为驱动力的突破路径

    "京东零售已经成为一家典型的以技术驱动为主的零售公司".在11月19日召开的 2019京东全球科技探索者大会上,京东零售集团CEO徐雷首次阐释了京东零售的智能化零售路径. 徐雷指出 ...

  10. Redis的数据结构和对象。

    一.简单动态字符串(simple dynamic string--SDS) Redis使用SDS表示字符串值,键值对都用SDS实现.SDS中的字符数组buf以空字符串结尾,好处是可以直接重用一部分C字 ...