Greedy:Graveyard Design(POJ 2100)
2023-12-01 22:40:07
题目大意,给定一个整数,要你找出他的平方和组合
太简单了。。。。不过一开始我储存平方和想降低时间,后来发现会超内存,直接用时间换空间了,游标卡尺法
#include <iostream>
#include <functional>
#include <algorithm>
#define MAX_N 10000001 using namespace std;
typedef long long LL_INT; static int store[MAX_N][];//只储存开始和结尾 void Inivilize(void); int main(void)
{
LL_INT n, sum, tmp;
int s, t, num; while (~scanf("%lld", &n))
{
sum = num = ; s = t = ;
while ()
{
while ((tmp = (LL_INT)t*(LL_INT)t) <= n && sum < n)
{
sum += tmp;
t++;
}
if (sum == n)
{
store[num][] = s; store[num][] = t;
num++;
}
if (sum < n)
break;
sum -= (LL_INT)s*(LL_INT)s; s++;
}
printf("%d\n", num);
for (int i = ; i < num; i++)
{
printf("%d ", store[i][] - store[i][]);
for (int j = store[i][]; j < store[i][]; j++)
printf("%d ", j);
printf("\n");
}
}
return EXIT_SUCCESS;
}
最新文章
- uva 11059 maximum product(水题)——yhx
- /bin/dd if=/path/to/source-file of=/path/to/backup-file
- 关于Switch结构利用
- API基础开发学习网址
- 训练趣题:黑与白 有A、B、C、D、E五人,每人额头上都帖了一张黑或白的纸。(此处用javascript实现)
- DEDECMS 关键字不能小于2个字节!
- 武汉科技大学ACM :1005: A+B for Input-Output Practice (V)
- java写文件时,输出不完整的原因以及解决方法
- 如何使用GOOLE
- AT24C02使用详解
- tensorflow第一篇---numpy模块
- python 操作RabbitMq详解
- css 多行文本的溢出显示省略号(移动端)
- TCP/IP 笔记 - 防火墙和网络地址转换
- 讲一讲MySQL如何防止“老鼠屎”类型的SQL语句
- Oracle时间的加减
- SQLSERVER 子查询中使用ORDER BY
- linux .zip 解压命令集
- pythonNET day05
- FusionCharts制作实时刷新图
热门文章
- php 选择排序法
- CF460D Little Victor and Set (找规律)
- C#中的抽象方法和虚方法有什么区别?
- Android Studio升级后,开启时遇到tools.jar seems to be not in Android Studio错误?
- mac 下 xampp 多域名 多站点 多虚拟主机 配置
- ajax提交Form
- 【转】CentOS环境下yum安装LAMP(Linux+Apache+Mysql+php)
- HDU 4803 Poor Warehouse Keeper
- CSS继承总结
- ios 异常捕获