1073. Square Country

Time limit: 1.0 second
Memory limit: 64 MB
There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament has passed a law about a land. According to the law each citizen of the country has a right to buy land. A land is sold in squares, surely. Moreover, a length of a square side must be a positive integer amount of meters. Buying a square of land with a side a one pays a2 quadrics (a local currency) and gets a square certificate of a landowner.
One citizen of the country has decided to invest all of his N quadrics into the land. He can, surely, do it, buying square pieces 1 × 1 meters. At the same time the citizen has requested to minimize an amount of pieces he buys: "It will be easier for me to pay taxes," — he has said. He has bought the land successfully.
Your task is to find out a number of certificates he has gotten.

Input

The only line contains a positive integer N ≤ 60 000 , that is a number of quadrics that the citizen has invested.

Output

The only line contains a number of certificates that he has gotten.

Sample

input output
344
3
Problem Author: Stanislav Vasilyev
Problem Source: Ural State Univerisity Personal Contest Online February'2001 Students Session
Difficulty: 161
 
题意:给出x,问要多少个完全平方数相加才能得到x。
分析:dp可以解决这个问题。
dp[i]表示i最少要多少个来组成、
dp[i] = min(d[i - j*j] + 1)
 
但是这题有更简单的做法。
根据定理,仍和正整数可以有四个完全平方数组成。
所以说最多四个数。
这样直接暴力即可。
当然,我是弱智,做的时候没有想到。
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n;
int dp[N]; inline void Input()
{
cin >> n;
} inline void Solve()
{
dp[] = , dp[] = ;
for(int i = ; i <= n; i++)
{
dp[i] = INF;
for(int j = ; j <= i / j; j++)
if(dp[i] > dp[i - j * j] + )
dp[i] = dp[i - j * j] + ;
}
cout << dp[n] << endl;
} int main()
{
freopen("e.in", "r", stdin);
Input();
Solve();
return ;
}

ural 1073. Square Country的更多相关文章

  1. 01背包 URAL 1073 Square Country

    题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...

  2. ural 1073.Square Country(动态规划)

    1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...

  3. Ural 1073 Square Country (DP)

    题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...

  4. URAL 1073 Square Country(DP)

    题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 ...

  5. ural 1698. Square Country 5(记忆化搜索)

    1698. Square Country 5 Time limit: 2.0 secondMemory limit: 64 MB The first arithmetical operation ta ...

  6. URAL 1097 Square Country 2 离散化

    一共才100个正方形,将所有正方形左下角和右上角的X坐标和Y坐标离散化,直接枚举新建公园的点的坐标即可. O(n^3)的时间复杂度. #include <cstdio> #include ...

  7. URAL 1698. Square Country 5(记忆化搜索)

    题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...

  8. ural1097 Square Country 2

    Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square count ...

  9. Square Country

    原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073 分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=mi ...

随机推荐

  1. maximum subarray problem

    In computer science, the maximum subarray problem is the task of finding the contiguous subarray wit ...

  2. Struts2之类型转换器

    一.类型转换器的应用场景 类型转换是OGNL的一部分,默认的八种基本类型.String.Date会使用类型转换,但是更复杂的类型转换就需要我们自定义了(虽然这个东西一般根本用不到),OGNL可以应用在 ...

  3. Android -- android:configChanges

    原文:http://jingyan.baidu.com/article/2fb0ba4056b25700f2ec5faf.html 从Android 3.2(API 13),如果你想阻止程序在运行时重 ...

  4. jQuery – 8.事件和事件参数

        事件 (*)JQuery中的事件绑定:$("#btn").bind("click",function(){}),每次都这么调用太麻烦,所以jQuery可 ...

  5. Java集合源码学习(二)ArrayList分析

    >>关于ArrayList ArrayList直接继承AbstractList,实现了List. RandomAccess.Cloneable.Serializable接口,为什么叫&qu ...

  6. SQL中的多表查询,以及JOIN的顺序重要么?

    说法是,一般来说,JOIN的顺序不重要,除非你要自己定制driving table. 示例: SELECT a.account_id, c.fed_id, e.fname, e.lname -> ...

  7. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  8. c++ 读取txt文件并输出到控制台

    代码如下: #include "stdafx.h" #include<iostream> #include<fstream> #include<cst ...

  9. 华为Mate8 NFC 时好时坏,怎么解决呢?

    拿起手机朝桌子上磕几下,nfc就好用了.这是花粉总结的,我也试过,很灵.注意要带套,摄像头朝下,头部低一点往下磕.因为nfc芯片在头部,估计是接触不良.

  10. 攻城狮在路上(叁)Linux(十七)--- linux磁盘与文件管理概述

    一.复习知识点: 1.扇区是最小的物理存储单位,大小为512bytes. 2.扇区组成一个圆,成为柱面,柱面是分区的最小单位. 3.第一个扇区很重要,因为包含了MBR(446字节)和分区表(64字节) ...