摘要: 由于输入数据数量很大,但是数据的范围很小,所以用计数排序,代码如下:View Code 1 #include 2 #include 3 4 int main() 5 { 6 int n, x, cnt[101]; 7 while(scanf("%d", &n) != EOF && n) 8 { 9 memset(cnt, 0, sizeof(cnt));10 for(int i = 0; i < n; i++)11 {12 scanf("%d", &x);13 c... 阅读全文
posted @ 2013-04-10 15:16 xiaobaibuhei 阅读(191) 评论(0) 推荐(0)
摘要: 将[1, n]从中间分成[1, n/2] 和[n/2+1, n]两个部分,分别包含n/2和(n+1)/2个数,将第二部分的数分别减去n/2+1, 第二部分变为[0, (n-1)/2], 第一部分包括第二部分,可得递推公式为:f(n) = f(n/2) + 1; 代码如下: View Code 1 #include 2 3 int f(int n) 4 { 5 return n == 1 ? 1 : f(n/2)+1; 6 } 7 8 int main() 9 {10 int n;11 while(scanf("%d", &n) != EOF)12 ... 阅读全文
posted @ 2013-04-09 18:32 xiaobaibuhei 阅读(160) 评论(0) 推荐(0)
摘要: 统计每个字母出现的次数,然后进行比较就行了。代码如下:View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int main() 7 { 8 #ifdef LOCAL 9 freopen("in", "r", stdin);10 #endif11 char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";12 char s[ 阅读全文
posted @ 2013-04-05 18:33 xiaobaibuhei 阅读(759) 评论(0) 推荐(1)
摘要: 这道题我把它想麻烦了,本来可以按绝对值直接排序的,我却把它们分成两组,再排序然后再从中选数进行合并,不知道怎么想的,不过倒是对sort函数又了解了一些。 下面是最初写的代码: View Code 1 #include <cstdio> 2 #include <algorithm> 3 #include <functional> 4 #include <cstdlib> 5 using namespace std; 6 7 const int maxn = 500000+10; 8 int color[2][maxn]; 9 10 int main 阅读全文
posted @ 2013-04-05 16:02 xiaobaibuhei 阅读(218) 评论(0) 推荐(0)
摘要: 很简单的一道题,可以直接模拟,需要注意的是以一个负数结束,不要被样例的-1误导了。 代码如下:View Code 1 #include <cstdio> 2 using namespace std; 3 4 int main() 5 { 6 int n, kase = 0; 7 while(scanf("%d", &n) != EOF) 8 { 9 if(n < 0) break;10 kase++;11 int num = 1, cnt = 0;12 while(num < n)13 ... 阅读全文
posted @ 2013-04-04 18:50 xiaobaibuhei 阅读(181) 评论(0) 推荐(0)
摘要: 对所有可能进行枚举,不过情况太多了,只需枚举第一行的情况,剩下来的就可以确定了。 代码如下:View Code 1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 20; 7 const int INF = 1000000000; 8 int n, a[maxn][maxn], b[maxn][maxn]; 9 10 int check(int s)11 {12 memset(b, 0, size 阅读全文
posted @ 2013-04-04 15:40 xiaobaibuhei 阅读(143) 评论(0) 推荐(0)
摘要: 将增加雕像后的间距看作1并用四舍五入的思想真是让人称赞,对两个雕像不会移动到同一位置的证明也很巧妙。 代码如下:View Code 1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 5 int main() 6 { 7 #ifdef LOCAL 8 freopen("in", "r", stdin); 9 #endif10 int n, m;11 while(scanf("%d%d", &n, &m) != EOF)1 阅读全文
posted @ 2013-03-31 20:34 xiaobaibuhei 阅读(209) 评论(0) 推荐(0)
摘要: 这道题自己分析时觉得挺麻烦的,没分析出来,只好看《训练指南》了,自己的分析和建模能力还是太弱了。 代码如下:View Code 1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 5 const int maxn = 1000000+10; 6 long long a[maxn], c[maxn]; 7 8 int main() 9 {10 #ifdef LOCAL11 freopen("in", "r", stdin);12 #endif13 i 阅读全文
posted @ 2013-03-30 20:55 xiaobaibuhei 阅读(230) 评论(0) 推荐(0)
摘要: 也是很直接的一道题,排序比较,无语的是又WA了一次,原因是输出格式"Case X: Y“我没看多输了个#号,好粗心啊。。。 代码如下:View Code 1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 5 const int maxn = 1000+10; 6 7 struct Soldier 8 { 9 int b,j;10 bool operator < (const Soldier& a) const{11 return j > a.j;12 }1 阅读全文
posted @ 2013-03-28 15:41 xiaobaibuhei 阅读(168) 评论(0) 推荐(0)
摘要: 很直接的一道题,排序比较就行了,不过还是超时了一次,因为一不小心写成死循环了。。。 代码如下: 1 #include 2 #include 3 using namespace std; 4 5 const int maxn = 20000+10; 6 int h[maxn], k[maxn]; 7 8 int main() 9 {10 #ifdef LOCAL11 freopen("in", "r", stdin);12 #endif13 int n, m;14 while(scanf("%d%d", &n, &m) 阅读全文
posted @ 2013-03-28 14:55 xiaobaibuhei 阅读(165) 评论(0) 推荐(0)