poj 2566
来源:互联网 发布:网络博客网站 编辑:程序博客网 时间:2024/06/12 01:44
这幅图便是尺取法怎么“取”的过程了。
整个过程分为4布:
1.初始化左右端点
2.不断扩大右端点,直到满足条件
3.如果第二步中无法满足条件,则终止,否则更新结果
4.将左端点扩大1,然后回到第二步
#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#define LL long longusing namespace std;vector<pair<LL, LL> > ans;void solve(LL n){ ans.clear(); LL s = 1, t = 1; LL sum = 0; while (s * s <= n) { while (t * t <= n && sum < n) { sum += t * t; t++; } if (sum == n) { ans.push_back(make_pair(s, t)); } sum -= s * s; s++; } int sz = ans.size(); printf("%d\n", sz); for (int i = 0; i < sz; i++) { printf("%d", ans[i].second - ans[i].first); for (int j = ans[i].first; j < ans[i].second; j++) { printf(" %d", j); } puts(""); }}int main(){ LL n; while (~scanf("%lld", &n)) { solve(n); } return 0;}
0 0
- poj 2566
- poj 2566
- 【POJ】2566
- 尺取法专题 POJ 3061 POJ 3320 POJ 2566
- Poj 2566(two pointers)
- POJ 2566 尺取法
- POJ 2566 尺取法
- POJ 2566 Bound Found
- POJ-2566-Bound Found
- poj 2566Bound Found
- poj 2566 尺取法
- poj 2566 Bound Found
- poj 2566 尺取法
- poj 2566 Bound Found
- poj 2566 Bound Found
- POJ 2566 Bound Found
- 【POJ】2566 Bound Found
- POJ 2566 Bound Found
- jQuery 判断是否包含在数组中 jQuery.inArray()
- HTTP常见状态码(404、400、500
- PAT1061
- 面向对象:ATM系统的分析类
- Google Guava官方教程
- poj 2566
- (十)RabbitMQ消息队列-高可用集群部署实战
- mongodb 在认证(auth)的情况下,配置主从(master & slave)
- RHEL-RH134-UNIT9--部署ftp文件共享服务
- Linux crontab定时任务
- jenkins部署多台服务器(window)tomcat提示401错误
- android 动画 补间动画,渐变动画 Tween Animation
- Android多媒体应用
- React Native ToolbarAndroid没显示