昨天做过一样的题:

平方和公式: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的更多相关文章

  1. ZOJ2345Gold Coins 简单分块

    昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1) #include<cstdio> #include<cstdlib> #include<iostream&g ...

  2. [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 ...

  3. 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 ...

  4. 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 ...

  5. csuoj 1119: Collecting Coins

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec  Memo ...

  6. Coins

    Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...

  7. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  9. POJ3260The Fewest Coins[背包]

    The Fewest Coins Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6299   Accepted: 1922 ...

随机推荐

  1. 《A_Pancers》团队项目用户验收评审

    团队项目用户验收评审 一.关于源代码管理的10 个问题: 1.你的团队的源代码控制在哪里?用的是什么系统?如何处理文件的锁定问题? 我们的项目都在github上面,用的win10系统,并且我们的文件没 ...

  2. spring boot开发 静态资源加载不出来

    spring boot 1.5 版本之前 不拦截静态资源 springboot 2.x版本 拦截静态资源 private static final String[] CLASSPATH_RESOURC ...

  3. Fisher线性判别分析

    Fisher线性判别分析 1.概述 在使用统计方法处理模式识别问题时,往往是在低维空间展开研究,然而实际中数据往往是高维的,基于统计的方法往往很难求解,因此降维成了解决问题的突破口. 假设数据存在于d ...

  4. Codeforces 735B - Urbanization

    735B - Urbanization 思路:贪心.人数少的城市住钱最多的那几个人. 不证明了,举个例子吧:a1<a2<a3<a4<a5 (a1+a2+a3)/3+(a4+a5 ...

  5. getpagesize.c:32: __getpagesize: Assertion `_rtld_global_ro._dl_pagesize != 0' failed

    为arm 编译 mysql , 执行的时候出现了这个问题. 好像是个bug, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=626379 重新编译 ...

  6. LeetCode--110--平衡二叉树

    问题描述: 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. 示例 1: 给定二叉树 [3,9,20,n ...

  7. 3-4 8精彩算法集合。struct(C,ruby) Ruyb类对象和结构体, 3-5

    在本章我遇到了c语言的struct数据,即自定义的数据结构.比如: struct edge { int u; int v; int w; }; 题目给了一组数据,用edge储存.需要按照w大小排序.我 ...

  8. Java字符串 API

    常用API

  9. python-day41--数据库---数据类型

    一.存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 二.mysql 数据类型 1.数字:(宽度指的是显示宽度,与存储无关)     不用指定宽度, ...

  10. sql表联接

    1.join: 表:erp_orders和erp_orders_products SELECT * FROM erp_orders_products AS products, erp_orders A ...