c&&c++
文章平均质量分 64
classmonster
这个作者很懒,什么都没留下…
展开
-
子集生成的两种方法
该算法来自--刘汝佳的算法竞赛入门经典。书中介绍了两种算法的核心代码,但却没有逐过程详细解说,另初学者看文字时很难看懂,遇到问题,是先要直接研究问题的细节呢还是先把问题搞清楚?我认为绝对应该先学习如何去解决问题,构造方法的框架,而不是先去研究细节。//方法一://思路:一次选出一个元素放到集合中[cpp] view plain copy #i转载 2017-05-12 18:22:38 · 358 阅读 · 0 评论 -
B - Ministry
DescriptionMr. F. wants to get a document be signed by a minister. A minister signs a document only if it is approved by his ministry. The ministry is anM-floor building with floors numbered f原创 2016-02-08 17:19:21 · 252 阅读 · 0 评论 -
判断质数的方法小结
判断质数的方法有很多种,这里只记录两种效率较高的方法。方法一:for(int i=0;i*i<=n;i++){ if(n%i==0) cout<<"n不是质数";}cout方法二:for(int i=0;i<=sqrt(n);i++){ if(n%i==0) cout<<"n不是质数";}cout推荐使用方法二。注意要取等号。原创 2016-03-18 23:14:58 · 463 阅读 · 0 评论 -
插入排序
// 插入排序 #includeusing namespace std;int main(){ const int arraySize=10; int data[arraySize] ={34,56,4,10,77,51,93,30,5,50}; int insert; for(int next=1;next<arraySize;next++) { int move=ne原创 2016-03-20 22:29:39 · 186 阅读 · 0 评论 -
1000. MyString Class
Description定义一个MyString类如下,该类有构造函数、拷贝构造函数、析构函数、成员函数和静态成员函数,有一个C字符串指针变量,还有一个静态成员变量numberOfObjects。请你完成类的实现。class MyString{public: MyString(const char*); MyString(int = 0, char =原创 2016-03-21 20:21:42 · 349 阅读 · 0 评论 -
用栈写的计算器
学习了栈后就用栈写了一个计算器,可以计算含有括号的表达式。但是没有写完对空格的处理,就是这个计算器无法处理数字间含有空格的格式错误。(不过应该不会很困难)最后用到了后缀表达式来计算。下面是代码:#include#include#include#includeusing namespace std;stack vals;stack ops;int compare(cha原创 2016-05-02 21:20:59 · 538 阅读 · 0 评论 -
Sicily 1001
1001. AlphacodeConstraintsTime Limit: 1 secs, Memory Limit: 32 MB DescriptionAlice and Bob need to send secret messages to each other and are discussing ways to encode theirmessages: Alice:原创 2016-05-08 16:15:04 · 310 阅读 · 0 评论 -
Scily 1002
1002. Anti-prime SequencesConstraintsTime Limit: 3 secs, Memory Limit: 32 MB DescriptionGiven a sequence of consecutive integers n,n+1,n+2,...,m, an anti-prime sequence is a rearrangement of原创 2016-05-28 23:00:12 · 308 阅读 · 0 评论 -
Sciliy 1007. To and Fro
ConstraintsTime Limit: 1 secs, Memory Limit: 32 MB DescriptionMo and Larry have devised a way of encrypting messages. They first decide secretly on the number ofcolumns and write the message (原创 2016-06-01 23:43:30 · 342 阅读 · 0 评论 -
分数化小数(decimal)完整版
题目:输入正整数a,b,c,输出a/b的小数形式,精确到小数点后c位。a,b 分析:这道题目保留位数要考虑进位,以及c=0的情况。修改了一下网上的代码。考虑了小数点的输出情况,以及保留0位小数的情况。#includeint num[101];int main(){ memset(num,0,sizeof(num)); int a,b,c; scanf("%d%d%d原创 2016-07-05 23:20:11 · 1125 阅读 · 0 评论 -
算法竞赛经典入门第三章习题
习题3-1 分数统计(stat)输入一些学生的分数,哪个分数出现的次数最多?如果有多个并列,从小到大输出。任务1:分数均不超过100的非负整数任务2:分数均不超过100的非负实数,但最多保留两位小数。这个类似单词统计词频,按字典序输出频率最高的那些。oj地址为: http://acm.dlut.edu.cn/problem.php?id=1132#include原创 2016-07-13 16:46:05 · 802 阅读 · 0 评论 -
B - AntiCAPS
DescriptionThe blonde Angela has a new whim: internet chats. Of course, as any blonde, she writes her messages using the upper case. You are the moderator of Angela's favorite chat and you're fe原创 2016-02-07 20:55:42 · 238 阅读 · 0 评论 -
H - Taxi
DescriptionPetr likes going by taxi. For him, it is not only the pleasure of a fast and comfortable ride, but also the opportunity to bargain with the driver over the fare. The bargaining betwee原创 2016-02-07 19:57:01 · 358 阅读 · 0 评论 -
HDU1005
#include#include#include#include#include#includeusing namespace std;int m[50];int main(){ int a,b,n; m[1]=1; m[2]=1; while(cin>>a>>b>>n) { if(a==0&&b==0&&n==0) break; for(int i=3;i原创 2016-02-07 19:26:29 · 165 阅读 · 0 评论 -
用归并排序处理逆序对问题
首先了解一下什么是逆序对,对于一个包含N个非负整数的数组A[1..n],如果有i A[ j ],则称(A[ i] ,A[ j] )为数组A中的一个逆序对。例如,数组(3,1,4,5,2)的逆序对有(3,1),(3,2),(4,2),(5,2),共4个。然后了解一下什么是归并排序: void Merge(int a[] , int low, int mid, int转载 2016-01-03 00:19:12 · 755 阅读 · 1 评论 -
梅森素数汇总
第1个梅森素数:当p=2时,M_2=(2^2)-1=3,位数为1位,发现于公元前300年左右。第2个梅森素数:当p=3时,M_3=(2^3)-1=7,位数为1位,发现于公元前300年左右。第3个梅森素数:当p=5时,M_5=(2^5)-1=31,位数为2位,发现于公元前100年左右。第4个梅森素数:当p=7时,M_7=(2^7)-1=127,位数为3位,发现于公元前300年左右。第5个梅森素数:当转载 2015-12-21 22:46:47 · 9764 阅读 · 0 评论 -
任意多边形面积
给定多边形的顶点坐标(有序),让你来求这个多边形的面积,你会怎么做?我们知道,任意多边形都可以分割为N个三角形,所以,如果以这为突破点,那么我们第一步就是把给定的多边形,分割为数个三角形,分别求面积,最后累加就可以了,把多边形分割为三角形的方式多种多样,在这里,我们按照如下图的方法分割:图1S点作为起始点(点1),a->e依次作为点2,3……。一个三角形的面积是转载 2015-12-19 17:52:30 · 443 阅读 · 0 评论 -
各整形的数据范围
unsigned int 0~4294967295 (2^32-1) int -2147483648~2147483647 (-(2^31-1)~2^31-1)unsigned long 0~4294967295 (2^32-1)long -2147483648~2147483647 (-(2^31-1原创 2016-01-24 17:28:10 · 624 阅读 · 0 评论 -
HDU1002
#includeusing namespace std;int main(){ int t; cin>>t; for(int i=1;i<=t;i++) { string str1,str2; cin>>str1>>str2; string s1=str1,s2=str2; int len1=str1.size(),len2=str2.size(); if原创 2016-01-27 17:23:52 · 210 阅读 · 0 评论 -
HDU1003 动态规划入门经典题
#includeusing namespace std;int main(){ int t; cin>>t; for(int i=0;i<t;i++)//这道题要求连续区间所求和最大,则每次累加的值必须是正数,才能达到和最大 { int temp,result,pos=0,start=0,end=0; //result代表所求的最大和 int n,a; cin>>n;原创 2016-01-27 22:52:32 · 283 阅读 · 0 评论 -
HDU1004
#include#include#include#includeusing namespace std;int main(){ int t; while(cin>>t) { if(t==0) break; string color[1001]; for(int i=0;i<t;i++) { cin>>color[i]; } sort(colo原创 2016-01-28 18:59:14 · 289 阅读 · 0 评论 -
HDU1006
#include#include#include#include#include#includeusing namespace std;double d;struct interval{ double left; double right;};interval solve(double a,double b){//解方程 //Angle<=v*t+a<=360-原创 2016-01-29 21:25:38 · 306 阅读 · 0 评论 -
贪吃蛇
想写一个贪吃蛇~先占个坑原创 2016-02-01 15:48:51 · 224 阅读 · 0 评论 -
HDU1007 求最短距离的点对
#include#include#include#includeusing namespace std;struct sys{ double x; double y;};sys num[100001],num1[100001],num2[100001];bool cmpy(sys dot1,sys dot2){ if(dot1.y==dot2.y) return do原创 2016-02-07 19:25:59 · 386 阅读 · 0 评论 -
算法竞赛入门经典chapter4:本章小结
编写一个 函数solve,给定浮点数a, b, c, d, e, f,求解方程组af + by = c, dx + ey = f;任务1:使用assert宏,让解不唯一时异常退出。#include#include#includedouble x=0,y=0;void solve(double a,double b,double c,double d,double e,dou原创 2016-07-15 21:15:51 · 339 阅读 · 0 评论 -
uva 401 回文词
我的方法写得不好。所以只贴代码了。#include#includechar cha[21];char tem[21];int palind(char a[]){ char tem[21]; strcpy(tem,a); int len=strlen(a); int i,m=len-1; for(i=0;i<len;i++) { tem[i]=a[m--]; } i原创 2016-07-20 12:39:56 · 218 阅读 · 0 评论 -
uva 10010
写这道题写了好久,我好菜。。最后还是参考了别人的代码。用常量表真的可以简化代码。#include#include#includeusing namespace std;int posx;int posy;int dx[]={1,-1,0, 0,-1,1, 1,-1};int dy[]={1,-1,1,-1, 0,0,-1, 1};char word_list[51][51];原创 2016-07-21 13:58:33 · 175 阅读 · 0 评论 -
1156. Binary tree
DescriptionYour task is very simple: Given a binary tree, every node of which contains one upper case character (‘A’ to ‘Z’); you just need to print all characters of this tree in pre-order.原创 2016-11-10 00:03:06 · 261 阅读 · 0 评论 -
折线分割平面
F - 折线分割平面Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDescription我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两原创 2015-12-19 17:35:44 · 322 阅读 · 0 评论 -
完全素数
Description设一个m位素数p由高到低每一位分别是a1, a2, ..., am. 定义一个素数是完全素数当且仅当对于任意k(1现在给定整数m(1Input 输入包含1个整数m(1Output输出若干行,每一行包含一个m位的完全素数,由小到大输出。 Sample Input Copy sample input to cl原创 2015-12-24 00:39:10 · 946 阅读 · 0 评论 -
递归解决全排列
DescriptionA permutation is a possible ordering of a set. For example, the permutations of a set {A,B,C} include ABC, ACB, BAC, BCA, CAB, CBA.The number of permutations of a set of N elements is原创 2015-12-24 11:19:00 · 437 阅读 · 0 评论 -
求最长不重复子串
求最长不重复子串有很多方法,比如hash啊。但是作为一个初学者(菜鸟)也只能用最笨的方法做了。代码如下:#includeusing namespace std;int main(){string s;int t;cin>>t;for(int h=0;h{cin>>s;int max=1;int n=s.size();for(int i=0原创 2015-12-26 21:07:48 · 288 阅读 · 0 评论 -
求右边区间的最大值
#include#includeusing namespace std;int a[100005],max1[100005];int main(){int n,m;scanf("%d%d",&n,&m);//cin>>n>>m;for(int i=0;i{scanf("%d",&a[i]);}int tem =a[n-1];for(int i=n原创 2015-12-15 19:57:48 · 409 阅读 · 0 评论 -
快速幂求模
C - 人见人爱A^BTime Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uSubmit StatusDescription求A^B的最后三位数表示的整数。 说明:A^B的含义是“A的B次方” Input输入数据包含多个原创 2015-12-19 16:49:51 · 370 阅读 · 0 评论 -
最短的基本字符串
Description有一字符串,是通过一个最基本的字符串不停复制拼接而成的。例如:1212121212121212是通过“12”不停的复制变成的。 第一次 12第二次 1212第三次 12121212第四次 1212121212121212 现在,给你这样一串字符串,希望你能找到合成这样一字符串的最短的基本字符串。原创 2015-12-28 20:00:46 · 703 阅读 · 0 评论 -
初次使用结构体解决学生成绩排列问题
Sorting students on gradesDescriptionRewrite Listing 6.12, GradeExam.cpp, to display the students in increasing order of the number of correct answers. Suppose the answers for all student原创 2016-01-06 17:10:51 · 719 阅读 · 0 评论 -
uva 133
#include#include#include#include using namespace std;int a[21];int main(){ int n,k,m; int temx=0,temy=0; while(cin>>n>>k>>m) { if(n==0&&k==0&&m==0) break; for(int i=0;i<原创 2016-08-14 15:19:12 · 174 阅读 · 0 评论 -
uva 101
#include#includeusing namespace std;vector pile[30]; vector tem;int n;void print(){ for(int i=0;i<n;i++) { printf("%d:",i); for(int j=0;j<pile[i].size();j++) {原创 2016-08-12 16:31:13 · 227 阅读 · 0 评论 -
uva 127
#include#include#include#include#include#includeusing namespace std;struct Card{ char face[2]; }card;vector > poc ; bool ismatch(struct原创 2016-08-05 21:52:55 · 200 阅读 · 0 评论 -
uva 10361
题目大意:读取字符串,每个测试例子有两行,第一行中有5个子串,中间用 ""分开。第二行有一个串,以“...”结尾。最后每个实例打印两行,第一行简单的把输入的第一行打印出来,只去掉 符号,第二行按照原来第二行的打印,并把三个点去掉,换成s4,s3,s2,s5。over此题写个函数读取s1~s5,getss()#include#includechar s1[101],s2[101],s转载 2016-07-21 17:09:02 · 207 阅读 · 0 评论