题目: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. C盘清理大作战

    C盘会随着使用时间慢慢变满(即使你不在C盘装程序),下面就记录几个C盘清理的方法: 1.使用清理软件清理C盘(360卫视,腾讯管家) 2.转移虚拟内存:计算机右键属性——高级管理设置——高级——性能- ...

  2. discuz!X2.5技术文档

    discuz!系统常量: DISCUZ_ROOT //网站根目录 TIMESTAMP   //程序执行的时间戳 CHARSET     //程序的编码类型 FORMHASH    //HASH值 其余 ...

  3. 医学影像工作站程序ProDicom的说明

    转载 http://blog.csdn.net/prodicom/article/details/4015064 注意:以下内容为转载,但保留了第一人称,请注意,以免造成不必要的麻烦. 医网联影像工作 ...

  4. Ubuntu安装google Gtest

    (1) 下载源码:http://code.google.com/p/googletest/gtest-1.7.0 (2013)gtest-1.7.0 (2010) (2) README编译指南126 ...

  5. SQL Server数据库备份(本机)

    基础的SQL Server数据库备份存储过程 /**************************************************************************** ...

  6. 【BZOJ 1031】[JSOI2007]字符加密Cipher

    Description 喜欢钻研问题的JS 同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法:把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作 ...

  7. 常见架构TLB miss处理方法(转)

    转自网站:http://blog.sina.com.cn/s/blog_633f462901018reb.html 0.       综述 总的来说TLB miss处理分为硬件处理和软件处理两种,硬件 ...

  8. (转)inux Read系统调用

    转载网址:http://my.oschina.net/haomcu/blog/468656 1. 什么是系统调用 2. read系统调用在内核空间的处理层次模型 3. 相关的内核数据结构 4. rea ...

  9. 深层解析:构建facebook应用商店推荐引擎

    Under the Hood: Building the App Center recommendation engine   As more apps on Facebook Platform ha ...

  10. 1201: [HNOI2005]数三角形 - BZOJ

    Description Input 大三角形的所有短边可以看成由(n+1)*n/2个单位三角形的边界组成.如下图的灰色三角形所示.其中第1排有1个灰色三角形,第2排有2个灰色三角形,……,第n排有n个 ...