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 ...
随机推荐
- 关于QT的QPainterPath::arcTo 详解
这个函数文档的意思就是画弧,看了文档也不太明白,自己做了demo终于明白了意思 移动到圆心,画180度半圆 void TestArcTo::paintEvent(QPaintEvent *) { QP ...
- 20170813pptVBA批量插入图片
Sub AddSldIn() Dim Pre As Presentation Dim NewSld As Slide Set Pre = Application.ActivePresentation ...
- Turbolinks
Turbolinks Turbolinks® makes navigating your web application faster. 功能: 自动优化导航. 无需server端配合.全HTML网页 ...
- RabbitMq windows 安装
参考官方网址: http://www.rabbitmq.com/install-windows-manual.html http://www.rabbitmq.com/install-windows. ...
- 原生js实现选项卡
html代码: <div class="tab"> <ul> <li class="selected">图片</li& ...
- HDU1506(真心不错的DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- UVA-10163 Storage Keepers (0-1背包)
题目大意:有n个仓库,m个应聘者,每人对应一个能力值.一个人可以看多个仓库,一间仓库只能被一个人看.如果一个能力为p的人看k间仓库,那么安全系数为p/k,求出最大的最小安全系数,并且求出在此情况下所有 ...
- VS2015新建项目时,左侧面板空白的解决方法
解决办法是: 1.进入"C:\Users\当前用户名(一般为administrator)\AppData\Local\Microsoft\VisualStudio\14.0" 2. ...
- ES curl bulk 导入数据
比如我们现在有这样一个文件,data.json: { " } } { "field1" : "value1" } 它的第一行定义了_index,_ty ...
- 在python中是没有NULL的,取而代之的是None,它的含义是为空
在python中是没有NULL的,取而代之的是None,它的含义是为空