BNU27937——Soft Kitty——————【扩展前缀和】
Soft Kitty
64-bit integer IO format: %lld Java class name: Main
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick's Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
laimao很喜欢这首“BigBang”里的“Soft Kitty”,这首歌的歌词很简单只有6句,"soft kitty, warm kitty, little ball of fur,happy kitty, sleepy kitty, purr purr purr.",她总是唱着玩儿。现在她无聊了决定换一个玩法,你来说出一个数字n,她来唱出第n(1 ≤ n ≤ 10^9)句歌词。注意了她的唱法是,第i次唱这首歌时,每句歌词重复2^(i-1)次。就是像这样,“soft kitty, warm kitty, little ball of fur, happy kitty, sleepy kitty, purr purr purr, soft kitty, soft kitty, warm kitty, warm kitty, little ball of fur, little ball of fur,……”你能帮助她输出第n句歌词么(不包括标点)?
Input
多组数据,第一行是一个整数K(0<K<=100),表示数据组数。接下来K行,每行一个数字n,表示你需要输出第n句歌词。
Output
输出对应歌词
Sample Input
8
1
2
3
4
5
6
7
8
Sample Output
soft kitty
warm kitty
little ball of fur
happy kitty
sleepy kitty
purr purr purr
soft kitty
soft kitty 错误点分析:前缀和计算时出错,数据范围没有考虑好,要用longlong用了int 解题思路:用前缀和的下标来映射唱n首歌。
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
long long f[50];
long long suf[50];
string ss[10];
void work(){ ss[0]="soft kitty";
ss[1]="warm kitty";
ss[2]="little ball of fur";
ss[3]="happy kitty";
ss[4]="sleepy kitty";
ss[5]="purr purr purr";
f[0]=0;
suf[0]=0;
f[1]=6;
suf[1]=6;
for(int i=2;i<50;i++){ f[i]=f[i-1]*2;
suf[i]=suf[i-1]+f[i];
}
}
void solve(long long m){ int i;
for(i=1;i<50;i++){ if(suf[i]>=m){ break;
}
}
m-=suf[i-1];
long long ti=(long long)pow(2,i-1);
if(m%ti==0){ cout<<ss[m/ti-1]<<endl;
}else{ cout<<ss[m/ti]<<endl;
}
}
int main(){ int K;
work();
scanf("%d",&K);
while(K--){ long long n;
scanf("%lld",&n);
solve(n);
}
return 0;
}
BNU27937——Soft Kitty——————【扩展前缀和】的更多相关文章
- es6学习笔记--字符串&数值&数组&函数&对象的扩展
这几天抽空学习了es6语法,关于字符串,数值,数组,函数以及对象的扩展,看到es6标准入门这本书,里面讲的扩展特别多,我认为有几部分在项目上用不到,就挑有用的当笔记学习了. 字符串的扩展 str.in ...
- 树(二)——二叉树
目录 本章主要讲解内容为: 树的非递归遍历算法,两种版本 树的扩展前缀以及前缀中缀构建方法 源码 btree.cpp btree.h 基础知识 一.定义 二叉树的递归定义:二叉树是每个结点最多含有两棵 ...
- ios/mac/COCOA系列 -- UIALertVIew 学习笔记
最近在学习ios开发,学习的书籍<ios7 Pragramming cookbook>,做笔记的目的以后方便查看.笔记形式是小例子,将书上的例子书写完整. UIAlertViewClass ...
- 综述-如何克服HTML5的“性工能”障碍
http://ask.dcloud.net.cn/docs HTML5自出现以来,几经风雨,虽看似很有前途,但实际使用问题太多,DCloud为此踩了无数坑.但我们从未放弃,我们加入了W3C,发起了 H ...
- webpack3_脚手架
webpack 记得 --save-dev 装入开发依赖 更新迭代快,需要有根据报错解决问题的能力,来融会贯通这个工具 这里的是 webpack3,其实已经到了 webpack4 了 采用了 w ...
- bsdiff差分算法
bsdiff的基本原理 bsdiff是由Conlin Percival开源的一个优秀的差分算法,而且是跨平台的.在Android系统中所使用的imgdiff本质上就是bsdiff. bsdiff的依据 ...
- Apache Ignite上的TensorFlow
任何深度学习都是从数据开始的,这是关键点.没有数据,就无法训练模型,也无法评估模型质量,更无法做出预测,因此,数据源非常重要.在做研究.构建新的神经网络架构.以及做实验时,会习惯于使用最简单的本地数据 ...
- tomcat启动(三)Catalina分析-load方法分析
load()方法按从上到下顺序分析(主要分析本人所没学过的知识点,其它略过...). Digester类作用 使用sax技术对xml进行解析 未开始解析时Digester.push(this)这个用来 ...
- ethereumjs/merkle-patricia-tree-2-API
SecureTrie src/secure.js:10-15 Extends Trie 扩展前缀树 You can create a secure Trie where the keys are au ...
随机推荐
- ASP.NET Core URL Rewrite中间件
URL重写是基于一个或多个预置规则修改请求URL的行为.URL重写在资源位置和访问地址之间创建了一种抽象,这样二者之间就减少了紧密的联系.URL重写有多种适用的场景: 临时或永久移动或替换服务器资源, ...
- ES_HEAD基本查询操作
一.基本查询操作 选择索引 设置type查询条件 搜索 操作说明如图: 二.must, must not,should的区别 must 返回的文档必须满足must子句的条件 ...
- Tips on rendering interiors
http://www.evermotion.org/tutorials/show/9824/making-of-morning-breakfast-tip-of-the-week http://www ...
- 项目前端打包工具从 NEJ 切换成 webpack
此文已由作者张磊授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 这里不讨论 NEJ 和 webpack 的优劣,仅从技术角度来探寻一下能否实现,以及实现的代价. 前言 上一篇 ...
- python之爬虫(二)爬虫的原理
在上文中我们说了:爬虫就是请求网站并提取数据的自动化程序.其中请求,提取,自动化是爬虫的关键!下面我们分析爬虫的基本流程 爬虫的基本流程 发起请求通过HTTP库向目标站点发起请求,也就是发送一个Req ...
- 五、Centos linux系统优化-实战
一.linux用户名和密码远程登陆的修改: windows默认的远程端口和管理员:user:administrator prot:3389在管理--->本地用户和组 进行权限设置或者修 ...
- 当页面滚动到距顶部一定高度时某DIV自动隐藏和显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [Maven实战-许晓斌]-[第二章]-2.2基于UNIX系统安装maven
>> >> >>3
- PHP删除一个目录下的所有文件,不删除文件夹
/*删除指定目录下的文件,不删除目录文件夹*/ function delFile($dirName){ if(file_exists($dirName) && $handle=open ...
- [Swift]在Swift中实现自增(++)、自减(--)运算符:利用extension扩展Int类
自增(++).自减(--)运算符主要用在For循环中,Swift有自己更简易的循环遍历方法,而且类似x- ++x这种代码不易维护. Swift为了营造自己的编码风格,树立自己的代码精神体系,已经不支持 ...