poj2739 poj2100 尺取法基础(二)
都是很简单的题目
poj2739素数打表+单点推移
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std; int cnt,n;
int flag[];
int prime[] = {,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
void dabiao(){ for(int i=;i<=;i++){
if(flag[i])continue;
prime[cnt++]=i;
for(int j=;j*i<=;j++)
flag[i*j]=;
}
} int main(){
dabiao();
while(scanf("%d",&n),n){
int l=,r=,sum=,ans=;
while(){
if(sum==n) ans++;
if(sum>=n) sum-=prime[l++];
else{
if(prime[r]<=n) sum+=prime[r++];
else break;
}
}
printf("%d\n",ans);
}
}
poj2100单点推移
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#define ll long long using namespace std; vector<ll> vec[];
ll cnt,n; int main(){
while(scanf("%lld",&n)==){
ll l=,r=,sum=;
for(int i=;i<=cnt;i++)
vec[i].clear();
cnt=;
while(){ if(sum==n){
cnt++;
for(int i=l+;i<=r;i++)
vec[cnt].push_back(i);
}
if(sum>=n){
l++;
sum-=l*l;
}
else {
if(r*r<=*n){
r++;
sum+=r*r;
}
else break;
}
}
printf("%lld\n",cnt);
for(int i=;i<=cnt;i++){
printf("%d ",vec[i].size());
for(int j=;j<vec[i].size();j++)
printf("%lld ",vec[i][j]);
puts("");
}
}
return ;
}
poj2739 poj2100 尺取法基础(二)的更多相关文章
- poj2739(尺取法+质数筛)
题意:给你一个数,问这个数能否等于一系列连续的质数的和: 解题思路:质数筛打出质数表:然后就是尺取法解决: 代码: #include<iostream> #include<algor ...
- poj2100(尺取法)
题意:选取一系列数,使得这些数的平方和等于n: 解题思路:尺取法扫一遍: #include<iostream> #include<algorithm> using namesp ...
- poj3061 poj3320 poj2566尺取法基础(一)
poj3061 给定一个序列找出最短的子序列长度,使得其和大于等于S 那么只要用两个下标,区间和小于S时右端点向右移动,区间和大于S时左端点向右移动,在这个过程中更新Min #include < ...
- POJ 3320 尺取法(基础题)
Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- POJ2739(尺取法)
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23931 ...
- BestCoder Round #86 二,三题题解(尺取法)
第一题太水,跳过了. NanoApe Loves Sequence题目描述:退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列.他在纸上随便写了一个长度为 nn ...
- POJ 尺取法
poj3061 Subsequence 题目链接: http://poj.org/problem?id=3061 挑战P146.题意:给定长度为n的数列整数a0,a1,...,a(n-1)以及整数S, ...
- 【尺取法】Jurisdiction Disenchantment
[尺取法]Jurisdiction Disenchantment PROBLEM 时间限制: 1 Sec 内存限制: 128 MB 题目描述 The Super League of Paragons ...
随机推荐
- Java主要版本平台
- Gulp小记
安装 总的来说,玩gulp的流程是这样的: 安装nodejs -> 全局安装gulp -> 项目安装gulp以及gulp插件 -> 配置gulpfile.js -> 运行任务 ...
- sql 各种常用函数
1.stuff函数 替换制定字符串 stuff(,,'许嵩') 结果: 最帅的许嵩最帅的我 2.replace函数 select replace('蜀云泉真是帅啊','蜀云泉','许嵩') 结果: 许 ...
- golang切片数据结构解释
1. 切片:切片是数组的一个引用,因此切片是引用类型 func main() { var arr = [6]int{1, 2, 3, 4, 5} var slice = arr[1:] fmt.Pri ...
- UESTC - 1167 一句话题意
---恢复内容开始--- 题目链接:https://vjudge.net/problem/UESTC-1167 请问从n*n的正方形左下角走到右上角且不越过对角线的情况总数模m的结果~ 分析: 还记得 ...
- web.py 模板错误记录
错误信息 Traceback (most recent call last): File , in process return self.handle() File , in handle retu ...
- round_robin 的几种取值
ATS-6 的round_robin可以有4种算法可以选择 true Traffic Server goes through the parent cache list in a round robi ...
- Shell结合Expect实现自动输入密码
Shell结合Expect自动输入密码示例 #!/bin/bash cd /data/live /usr/bin/expect <<-EOF spawn git clone "s ...
- WF控制台工作流(1)
简单使用WF工作流示例: using System; using System.Linq; using System.Activities; using System.Activities.State ...
- Java SE之基本程序设计结构
概述: 0.注释 1.基本数据类型(有且仅有8个): 1.1 整型:int,short,long,byte(表示一个字节,[-128,127]) 1.2 ...