#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; char code[1000][100]; bool solve(int p) { for(int i = 1; i < p; i++) { int len = min(strlen(code[i-1]), strlen(code[i])); int j; for(…
  七种qsort排序方法 <本文中排序都是采用的从小到大排序> 一.对int类型数组排序 int num[100]; Sample: int cmp ( const void *a , const void *b ){return *(int *)a - *(int *)b;} qsort(num,100,sizeof(num[0]),cmp); 二.对char类型数组排序(同int类型) char word[100]; Sample: int cmp( const void *a , co…
1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1.2.1 Milking Cows 挤牛奶 (milk2.pas/c/cpp) 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开始2100秒结束.期间最长的至…
吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂. 题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子串. 直接简单粗暴的去比较就可以了. 这是原题:   Immediate Decodability  An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is th…
题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计数,easy!!! 代码如下: #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int maxn = 5…
假设数字1~i-1已经全部归位,则第i到第n个数为无序区间. 如果i在无序区间的前半段,那么直接将i换到第i个位置上. 否则先将i换到无序区间的前半段,再将i归位.这样每个数最多操作两次即可归位. #include <bits/stdc++.h> using namespace std; + ; int a[maxn]; vector<pair<int, int> > ans; void op(int L, int R) { ans.push_back(make_pai…
An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the prefix of a code for another symbol. We will assume for this problem that all codes are in binary, that no two codes within a set of codes are the sa…
qsort(数组名,数组长度,数组中每个元素大小,compare); compare函数的写法决定了排序是升序还是降序.需要#include<stdlib.h> 例如: int compare(const void*a,const void*b){return *(int*)a-*(int*)b;} 示例:qsort(a,10,sizeof(int),compare) //假设已定义了整型数组a[10] 升序排序的写法,如果是:return *(*int)b-*(int*)a 就是降序,不论是…
 冒泡,快排都是常见的排序方法,这里介绍用头文件里的qsort函数排序.只是自己要先一个cmp函数. #include<stdlib.h>//qsort的头文件 int a[100]={0,2,4,1,5,7,3,8,9}; //要排序的数组 struct Person//要排序的结构体 { char num[20]; char name[100]; int score; int sum; double P; }man[100]; 1.给数组a[]排序 int cmp_1(const vo…
qsort包括在<stdlib.h>头文件里.此函数依据你给的比較条件进行高速排序,通过指针移动实现排序. 排序之后的结果仍然放在原数组中.使用qsort函数必须自己写一个比較函数. 函数原型: void qsort ( void * base, size_t num, size_t size, int ( * comparator ) ( const void *, const void * ) ); 使用方法以及參数说明: Sorts the num elements of the arr…