poj 水题系列
题目:http://poj.org/problem?id=3006
筛选法求素数
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std; int prime[];//代表是否是素数
int main()
{
int s,max=;
int x,y,z,i; s=;
prime[]=prime[]=;
prime[]=; for(int i=; i<max; i++)
prime[i]=i%==?:;
int t=(int)sqrt(max*1.0); for(int i=; i<=t; i++)
if(prime[i])
for(int j=i*; j<max; j+=i)
prime[j]=; while(cin>>x>>y>>z&&(x!=||y!=||z!=))
{
for(i=x; z; i+=y)
{
if(prime[i])
z--;
}
cout<<i-y<<endl;
}
return ;
}
http://poj.org/problem?id=2105
函数参考:http://www.cnblogs.com/sunyubo/archive/2009/07/21/2282256.html
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
char str[]; int main()
{
int t,i,j,x;
cin>>t;
for(j=; j<=t; j++)
{
for(i=; i<=; i++)
{
scanf("%8s",str);
x=strtol(str,,);//strtol函数将字符串转换为n进制数,这里是2
if(i!=)
printf("%d.",x);
else
printf("%d\n",x);
}
}
return ;
}
http://poj.org/problem?id=1013
参考:http://www.cppblog.com/guyuecanhui/articles/88302.html
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std; int a[],b[];//a为当前状态,b为上一个状态
int main()
{
int t,i,j,f;
char s1[],s2[],s3[];
scanf("%d",&t);
getchar();
while(t--)
{
memset(a,-,sizeof(a));
for(i=; i<=; i++)
{
scanf("%s%s%s",s1,s2,s3);
getchar();
if(strcmp(s3,"even")==)
{
for(j=; j<strlen(s1); j++)
{
a[s1[j]]=a[s2[j]]=;
}
}
if(strcmp(s3,"up")==)
{
memcpy(b,a,sizeof(a));
memset(a,,sizeof(a));//与下面联系,对其他的添加信任
for(j=; j<strlen(s1); j++)
{
a[s1[j]]=;a[s2[j]]=;
}
for(j=; j<=; j++)
{
if(a[j]!=b[j] && b[j]>=)//如果上一个状态有怀疑,而且两次怀疑不一样,添加信任
a[j]=;
}
} if(strcmp(s3,"down")==)
{
memcpy(b,a,sizeof(a));
memset(a,,sizeof(a));
for(j=; j<strlen(s1); j++)
{
a[s1[j]]=; a[s2[j]]=;
}
for(j=; j<=; j++)
{
if(a[j]!=b[j] && b[j]>=)
a[j]=;
}
}
}
for(i=; i<=; i++)
{
if(a[i]>)
{
f=a[i];
break;
}
}
if(f==)
printf("%c is the counterfeit coin and it is light.\n",i);
else if(f==)
printf("%c is the counterfeit coin and it is heavy.\n",i);
}
return ;
}
poj 水题系列的更多相关文章
- nyoj 1208——水题系列——————【dp】
水题系列 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给你一个有向图,每条边都有一定的权值,现在让你从图中的任意一点出发,每次走的边的权值必须必上一次的权 ...
- POJ 水题若干
POJ 3176 Cow Bowling 链接: http://poj.org/problem?id=3176 这道题可以算是dp入门吧.可以用一个二维数组从下向上来搜索从而得到最大值. 优化之后可以 ...
- POJ 水题(刷题)进阶
转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...
- Tarjan水题系列(5):最大半连通子图 [ZJOI2007 luogu P2272]
题目 大意: 缩点后转为求最长链的长度和最长链的个数 思路: 看懂题就会做系列 长度和个数都可以拓扑排序后DP求得 毕竟是2007年的题 代码: 如下 #include <cstdio> ...
- COdevs 天梯 水题系列
1203 判断浮点数是否相等 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 给出两个浮点数,请你判断这两个浮点数是否相等 输入 ...
- Tarjan水题系列(4):HAOI2010 软件安装
题目: 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和最大). ...
- Tarjan水题系列(3):HNOI2006 潘多拉的魔盒
题目: 链接 大意: 盒子与盒子之间的关系构成一个有向图 求图上包含节点数最多的路径的节点数 思路: 有向图上求包含节点数最多的路径的节点数 可直接使用tarjan缩点后拓扑dp求得 在此不赘述 此题 ...
- 【POJ水题完成表】
题目 完成情况 poj1000:A+B problem 完成 poj1002:电话上按键对应着数字.现在给n个电话,求排序.相同的归一类 完成 poj1003:求最小的n让1+1/2+1/3+...+ ...
- POJ水题 1298
#include "stdafx.h" #include <iostream> #include <string> using namespace std; ...
随机推荐
- Div 内部所有元素 全部垂直对齐
http://stackoverflow.com/questions/7273338/how-to-vertically-align-an-image-inside-div How it works: ...
- JS中的!=、== 、!==、===的用法和区别。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 var num = 1; var str = '1'; var test = 1; t ...
- Arcgis 10.1中空间连接功能
空间链接的作用:将面上的所有点的值加起来取平均值.赋值给面属性.(我们可以定义右击——定义合并规则 连接要素的字段映射参数中指定的合并规则仅适用于连接要素中的属性,且仅适用于多个要素与目标要素匹配 ( ...
- Arcgis投影变换后图像变深的问题
首先投影时,重采样方式选择nearest最邻近采样法,不改变投影后图像的DN值。 然后双击投影后图像,在符号系统中选择RGB——拉伸类型改为:无(默认是标准差拉伸)
- PDF ITextSharp
示例源码 //Document:(文档)生成pdf必备的一个对象,生成一个Document示例 Document document = new Document(PageSize.A4, 30, 30 ...
- jQuery 点击按钮刷新页面
//页面加载时绑定按钮点击事件 $(function () { $("#按钮id").click(function () { refresh(); }); }); //点击按钮调用 ...
- Struts 2 Tutorials
http://www.dzone.com/tutorials/java/struts-2/struts-2-tutorial/struts-2-tutorial.html http://struts. ...
- Oracle创建序列
CREATE SEQUENCE IF NOT EXISTS seq_fund_execute
- python学习笔记23(时间与日期 (time, datetime包))
Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime. time包 time包基于C语言的库函数(library functions).Python的解释器通 ...
- Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=9 [题解]: 这题卡了一下,卡在负数的情况,负数输出 0 这题主要找到一 ...