摘要: 题目:给定两个只含大写字母的等长字符串,问两者之间是否存在一一映射分析:考察一一映射的概念,将两个字符串分别作字母统计,再按字母出现个递增的顺序排序(排列的是每个字母出现的个数),如果排序后结果一样那么两者是一一映射 1 #include <stdio.h> 2 #include <iostream> 3 #include <string> 4 #include <algorithm> 5 #define zz 6 using namespace std; 7 int main(){ 8 #ifndef zz 9 freopen("in 阅读全文
posted @ 2013-02-10 17:02 ChrisZZ 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 题意就不说了,简单的二分就可以了,应当是算法初学者的一个Hello world程序吧!只是建议用乘法去做,不要用除法去求解~注意输入的终止符是负数 1 #include <stdio.h> 2 #include <iostream> 3 using namespace std; 4 int main(){ 5 int n, cas = 1; 6 while(scanf("%d", &n)!=EOF && n>0){ 7 int i = 1, cnt = 0; 8 while(true){ 9 if(i>=n) br 阅读全文
posted @ 2013-02-10 15:39 ChrisZZ 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题意:给出n个数,请按照他们绝对值的递增顺序排序,且相邻元素不能有相同符号(必须一个大于0,一个小于0),问这样操作后最多有多少个元素分析:先调用sort排序然后逐个判断相邻两个元素的乘积是否小于0. 注意结果会溢出,不能用int,可以用double,当然用bool型变量标记也可以 1 #include <stdio.h> 2 #include <iostream> 3 #include <vector> 4 #include <algorithm> 5 #include <math.h> 6 #define zz 7 using n 阅读全文
posted @ 2013-02-10 15:37 ChrisZZ 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 题意:给你一个m行n列的举行巧克力切成mn个1*1的方块,问需要切多少刀?每一刀只能沿着直线切,不能用一刀同时切割两块巧克力。分析:简单计算后发现ans=m*n-1 1 #include <stdio.h> 2 #include <iostream> 3 #define zz 4 using namespace std; 5 int main(){ 6 #ifndef zz 7 freopen("in.txt", "r", stdin); 8 #endif 9 int a, b;10 while(scanf("%d%d& 阅读全文
posted @ 2013-02-10 15:32 ChrisZZ 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 题意:有一块草坪,长为l,宽为w,再起中心线的不同位置处装有n个点状的喷水装置。每个喷水装置i可以将以它为中心,半径为ri的圆形区域润湿,请选择尽量少的喷水装置,把整个草坪全部润湿。分析:对于直径小于宽度的喷水装置其实可以忽略,剩下的问题转换成了最小区间覆盖问题,即:用最少数量的区间去覆盖给定的区间 1 #include <stdio.h> 2 #include <iostream> 3 #include <algorithm> 4 #include <math.h> 5 #define zz 6 using namespace std; 7 c 阅读全文
posted @ 2013-02-10 15:29 ChrisZZ 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 题意:输入两个字符串s和t,判断是否可以从t种删除0个或多个字符(其他字符不变),得到字符串s,比如abcde可以得到bce,单数无法得到dc分析:简单模拟即可 1 #include <stdio.h> 2 #include <iostream> 3 #include <string> 4 #define zz 5 using namespace std; 6 int main(){ 7 #ifndef zz 8 freopen("in.txt", "r", stdin); 9 #endif10 string s, t 阅读全文
posted @ 2013-02-10 15:24 ChrisZZ 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 题意给定n个正整数,你的任务是把他们连接成一个最大的整数,比如,123,124,56,90有24种连接方法,最大的结果是9056124123分析:自己写比较函数cmp(s, t), 比较s+t 与t+s的大小即可。#include <stdio.h>#include <iostream>#include <string>#include <vector>#include <algorithm>#define zzusing namespace std;bool cmp(const string &s, const string 阅读全文
posted @ 2013-02-10 15:18 ChrisZZ 阅读(164) 评论(0) 推荐(0) 编辑
摘要: #pragma warning(disable:4786)#include #include #include #include #include #define zzzusing namespace std;int min(int a, int b){ return ab?a:b;}const int MAXN = 1000 + 5;int cnt;mapid;int ID(string s){ if(!id.count(s)) id[s]=cnt++; return id[s];}struct ZZ{ int p, q;};vectorzz[MAXN];int b, n;bool erfe 阅读全文
posted @ 2013-02-09 22:02 ChrisZZ 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 题意:给出一个a*b的网格,在网格上取不共线的三点构成三角形,求三角形总数。分析:就是一一道简单的组合数计算题目,设总结点数为n,则取三个节点的个数为C(n,3),然后减去横向、竖向、斜向的三点共线的个数即可,斜线三点共线等价于所枚举的矩形的长宽成倍数关系,即gcd不为1代码如下:#include #include using namespace std;long long gcd(long long a, long long b){ if(a%b==0) return b; return gcd(b, a%b);}int main(){ long long a, b; ... 阅读全文
posted @ 2013-02-09 08:19 ChrisZZ 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 题意:任取斐波那契数列中一项f[i],若对于所有j解法:这题的理论分析在黑书上有,结论是从第五项开始下标为素数的斐波那契数都是斐波那契素数#include #include const int MAXN = 250010;;int prime[25010];bool isprime[MAXN];long double fib[MAXN];int main(){ int i, j; for(i=0; i1e9){ fib[i]/=10; flag = true; } } int n; while(scanf("%d", &n)!=EOF) printf("% 阅读全文
posted @ 2013-02-09 08:17 ChrisZZ 阅读(190) 评论(0) 推荐(0) 编辑