摘要: 秒杀题,计算回文子串数。#include <iostream>#include <string>using namespace std;string str;int fun(int strl,int strr){ int num=0; while(strl>=0&&strr<str.length()) { if(str[strl]==str[strr]) { num++; strl--; strr++; } else break; } return num;}int main(){ int n,i; while(cin>>str) 阅读全文
posted @ 2011-04-20 22:45 watana 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 秒杀题,给出一个数n,判断所否可以分解为两个素数相乘。和1951差不多。打出素数表,再枚举判断。 阅读全文
posted @ 2011-04-20 22:01 watana 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 秒杀题。题意为,输入一串字符。按照给出的规则输出一个数字或者不输出。还有相邻字符为同一个规则的话,则输出一个即可。#include<iostream>#include<string>using namespace std;int num[26]={0,1,2,3,0,1,2,0,0,2,2,4,5,5,0,1,2,6,2,3,0,1,0,2,0,2};int main(){ string str; int i; while(cin>>str) { for(i=0;i<str.length()-1;i++) { if(num[str[i]-'A& 阅读全文
posted @ 2011-04-20 20:17 watana 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 是一个水题。给一个数字n,计算出两个素数,使得他们的和等于n若没有则输出"Goldbach's conjecture is wrong."可以先做一个素数表,然后再枚举看2到n/2之间是否有满足条件的素数对。 阅读全文
posted @ 2011-04-20 19:53 watana 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 这个题目是黑书上面作为贪心算法的例题,就是枚举最远到X湖时,最多的钓鱼数,减掉在路上的时间,就相当于在湖点之间的瞬移。再从1到N个湖枚举,可以得到一个最优的序列。还有一些测试数据。#include<iostream>#include<cstring>#include<cstdio>using namespace std;struct lakes{ int f,d,t;}l[30],ll[30];int tmax[30],tt[30],fishmax;int main(){ //freopen("/home/master/文档/workspace/i 阅读全文
posted @ 2011-04-20 19:45 watana 阅读(389) 评论(0) 推荐(0) 编辑