题目: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 水题系列的更多相关文章

  1. nyoj 1208——水题系列——————【dp】

    水题系列 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述     给你一个有向图,每条边都有一定的权值,现在让你从图中的任意一点出发,每次走的边的权值必须必上一次的权 ...

  2. POJ 水题若干

    POJ 3176 Cow Bowling 链接: http://poj.org/problem?id=3176 这道题可以算是dp入门吧.可以用一个二维数组从下向上来搜索从而得到最大值. 优化之后可以 ...

  3. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  4. Tarjan水题系列(5):最大半连通子图 [ZJOI2007 luogu P2272]

    题目 大意: 缩点后转为求最长链的长度和最长链的个数 思路: 看懂题就会做系列 长度和个数都可以拓扑排序后DP求得 毕竟是2007年的题 代码: 如下 #include <cstdio> ...

  5. COdevs 天梯 水题系列

    1203 判断浮点数是否相等 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 给出两个浮点数,请你判断这两个浮点数是否相等 输入 ...

  6. Tarjan水题系列(4):HAOI2010 软件安装

    题目: 现在我们的手头有N个软件,对于一个软件i,它要占用Wi​的磁盘空间,它的价值为Vi​.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi​的和最大). ...

  7. Tarjan水题系列(3):HNOI2006 潘多拉的魔盒

    题目: 链接 大意: 盒子与盒子之间的关系构成一个有向图 求图上包含节点数最多的路径的节点数 思路: 有向图上求包含节点数最多的路径的节点数 可直接使用tarjan缩点后拓扑dp求得 在此不赘述 此题 ...

  8. 【POJ水题完成表】

    题目 完成情况 poj1000:A+B problem 完成 poj1002:电话上按键对应着数字.现在给n个电话,求排序.相同的归一类 完成 poj1003:求最小的n让1+1/2+1/3+...+ ...

  9. POJ水题 1298

    #include "stdafx.h" #include <iostream> #include <string> using namespace std; ...

随机推荐

  1. gridview 字段没有绑定由于column visible= false

    由于gridview column visible=false, 后面执行gridview databound()操作 不会将数据绑定到相关的单元格,其实这个时候我们希望绑定数据只是不显示而已. 可以 ...

  2. 超棒的阿里巴巴矢量图标库——支持IE6

    Iconfont.cn 是由阿里巴巴UX部门推出的矢量图标管理网站,也是国内首家推广Webfont形式图标的平台.网站涵盖了1000多个常用图标并还在持续更新 中,Iconfont平台为用户提供在线图 ...

  3. Flex读文本文件

    布局: <s:Group id="> <s:Rect width="100%" height="100%"> <s:fi ...

  4. 论Oracle字符集“转码”过程

    本文将通过实验来演示一下Oracle字符集“转码”的确认过程. 1.实验环境说明 客户端是Windows XP操作系统的SQL*Plus程序,客户端字符集是936(对应Oracle的ZHS16GBK字 ...

  5. Extjs4 treePanel异步加载菜单(后台从数据库读取)

    运行环境:springMVC+mybatis 一.建表 说明:0表示此节点为非叶子节点,即此节点还包括了子节点:1表示此节点为叶子节点,即此节点没有子节点.:关于图标iconCls是从Extjs的文件 ...

  6. No qualifying bean of type [com.shyy.web.service.TreeMapper] found for dependency

    异常信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sp ...

  7. hdu 1087

    动规  d[i]记录以第 i 个数结尾的最大值 #include <cstdio> #include <algorithm> #include <cstring> ...

  8. scikit-learn安装

    1.依赖包: Cython.rose.numpy.scipy.lapack.atlas http://blog.chinaunix.net/uid-22488454-id-3978860.html

  9. ValueError: Attempted relative import in non-package

    执行:python deom/scripts/populate.py ValueError: Attempted relative import in non-package solve:python ...

  10. Maven Source jar

    http://blog.csdn.net/symgdwyh/article/details/4407945