ZOJ2345Gold Coins
昨天做过一样的题:
平方和公式:n*(n+1)*(2n+1)/6
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int a[],num;
int b[];
int _S()
{
char c=getchar();int s=;
while(c<''||c>'') c=getchar();
while(c>=''&&c<=''){s=s*+c-'';c=getchar();}
return s;
}
void _db()
{
for(int i=;i<=;i++)
a[i]=(i+)*i/;
for(int i=;i<=;i++)
b[i]=i*(i+)*(*i+)/;
return ;
}
void _get(int v)
{
int tmp,ans;
for(int i=;i<=;i++)
if(a[i]<=v) tmp=i;//当然也可以用二分查找或者lower_bound
ans=b[tmp];
ans+=(v-a[tmp])*(tmp+);
printf("%d %d\n",v,ans);
return ;
}
int main()
{
_db();
int T,n,x;
T=_S();
while(T--){
while(true){
x=_S();
if(x==) break;
_get(x);
}
if(T) printf("\n");
}
return ;
}
ZOJ2345Gold Coins的更多相关文章
- ZOJ2345Gold Coins 简单分块
昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1) #include<cstdio> #include<cstdlib> #include<iostream&g ...
- [LeetCode] Arranging Coins 排列硬币
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- csuoj 1119: Collecting Coins
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec Memo ...
- Coins
Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- POJ3260The Fewest Coins[背包]
The Fewest Coins Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6299 Accepted: 1922 ...
随机推荐
- [ios][swift]swift中如果做基本类型的转换
在swift中如果做基本类型的转换的?比如Int -> Float(Double)Double -> 保留两位小数String -> IntDouble -> String 有 ...
- jq的attr()与prop()之间区别
1.attr() 一直存在,prop() 仅存在于 jq-1.6 及其之后 2.新版本jq使用细节: 2.1 自定义添加至dom节点的属性,用attr获取 2.2 表单类checked.selecte ...
- RabbitMQ入门_04_Exchange & Binding
如果你比较细心,你会发现 HelloWorld 例子中的 Sender 只申明了一个 hello 队列,然后就开始向默认 Exchange 发送路由键为 hello 的消息.按照之前 AMQP 基本概 ...
- Codeforces 912E - Prime Gift
912E - Prime Gift 思路: 折半枚举+二分check 将素数分成两个集合(最好按奇偶位置来,保证两集合个数相近),这样每个集合枚举出来的小于1e18的积个数小于1e6. 然后二分答案, ...
- smarty课程---smarty3的安装和使用
smarty课程---smarty3的安装和使用 一.总结 一句话总结:smarty 是什么,就不多说了,用过php,接触过php的人都对smarty 再熟悉不过了.它是一个很强大的代码分离软件,作为 ...
- java服务突然被挂掉,停止服务处理方案
一.问题背景 该问题出现在我们测试环境.测试环境部署了很多java应用. 其中一个数据服务(主要提供订单交易数据聚合查询),用着用着就服务挂掉了也就是进程没有了. 二.分析过程 1.了解服务器配置 ...
- Android发展历程
Android历代版本的命名: 我们都是知道,安卓系统的历来的名称都是很有意思的,下面无限互联Android培训的老师归纳了一下:Android在正式发行之前,最开始拥有两个内部测试版本,并且以著名的 ...
- hdu2955(概率DP)
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...
- Repeater中服务器按钮
protected void Button1_Click(object sender, EventArgs e) { Button btn = sender as ...
- 贴心的vs 备注提醒功能