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 ...
随机推荐
- Qt532_字符编码转换
1.测试代码: // http://blog.csdn.net/changsheng230/article/details/6588447 QString str = QString::fromLoc ...
- [库][c++]tinyxml2使用小结
参考:http://blog.csdn.net/educast/article/details/12908455 1.配置TinyXML2 去这里把项目弄下来,然后解压,我们之需要里面的tinyxml ...
- Java实现日历小程序【代码】
这个没啥难点的,主要是界面设计吧 界面就是这个样子 运行时请在src同目录下放上我女神的照片 -----------------------------------代码如下-------------- ...
- LeetCode--190--颠倒二进制位
问题描述: 颠倒给定的 32 位无符号整数的二进制位. 示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 000000101001010000 ...
- 20170711筛选OutLook主题并转发
Sub 筛选OutLook主题并转发() On Error Resume Next Dim OutApp As Application Set OutApp = Application Dim Out ...
- codeforces 1042d//Petya and Array// Codeforces Round #510 (Div. 2)
题意:给出一个数组,求其中和小于t的区间数. 先计算前缀和数组sum[i].对当前的sum[i],查询树状数组中有几个比(sum[i]-t)大的数,那么用sum[i]减它就是一个合法区间.再将当前的s ...
- Charles安装破解、抓取https请求及常见问题解决方法
现在基本大部分网站都使用了https,所以要想抓到https的请求,首要任务是先有工具:charles.fiddler,先介绍下charles针对https请求的抓取方法,此方法兼容windows和m ...
- Java网络编程和NIO详解8:浅析mmap和Direct Buffer
Java网络编程与NIO详解8:浅析mmap和Direct Buffer 本系列文章首发于我的个人博客:https://h2pl.github.io/ 欢迎阅览我的CSDN专栏:Java网络编程和NI ...
- spring boot学习(十三)SpringBoot缓存(EhCache 2.x 篇)
SpringBoot 缓存(EhCache 2.x 篇) SpringBoot 缓存 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManag ...
- Java live template[在此处输入文章标题]
Java -Dfile.encoding=UTF-8 提示键盘 功能 Logg private final Logger log = Logger.getLogger(this.getClass()) ...