zrq495
www.zrq495.com
摘要: 水题!看懂题马上就能写出来。 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int T=1, n, i, sum; 6 int a[60]; 7 while(cin >> n, n) 8 { 9 sum=0;10 int ct=0;11 for (i=0; i<n; i++)12 {13 cin >> a[i];14 sum+=a[i];15 }16 ... 阅读全文
posted @ 2012-07-24 21:16 zrq495 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 当k=0时,n=3;当k!=0时,找最小的n,使sum=1+2+3+....+n >= |k|,且sum为偶数。代码:#include<iostream>using namespace std;int main(){ int T, i, j, k, sum, p; cin >> T; while(T--) { sum=0; cin >> k; if (k < 0) k=-k; if (!k) cout << "3" << endl; else { i=0; ... 阅读全文
posted @ 2012-07-24 20:56 zrq495 阅读(328) 评论(2) 推荐(0) 编辑
摘要: 水题,简单。 1 #include<iostream> 2 #include<cstring> 3 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 char str[10000];10 cin >> n;11 while(n--)12 {13 cin >> str;14 if (!strcmp(str, "1") || !strcmp(str, "4") || !strcmp(str, "78"))15 cout << 阅读全文
posted @ 2012-07-24 19:19 zrq495 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 求两个正方体的带有的颜色是否相同。最少2次旋转就可以得到12种情况。ac代码: 1 #include<iostream> 2 #include<stdio.h> 3 4 using namespace std; 5 6 int main() 7 { 8 int i, j; 9 char c1[7], c2[7], str[13];10 while(scanf("%s", str)!=EOF)11 {12 for (i=0; i<6; i++)13 c1[i]=str[i];14 for (; i<12;... 阅读全文
posted @ 2012-07-24 16:04 zrq495 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 对角线上的数字满足 an = n * (n - 1) + 1;再通过列或者行的奇偶性以及与对角线数字的关系得到坐标。代码如下: 1 #include<iostream> 2 #include<cmath> 3 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 while(cin >> n, n)10 {11 int c=(int)ceil(sqrt(n));12 int a=c*(c-1)+1;13 if (c & 1)14 {15 ... 阅读全文
posted @ 2012-07-24 14:15 zrq495 阅读(351) 评论(0) 推荐(0) 编辑
摘要: Problem Descriptionjxust_acm 队的同学都知道Xianbin5的英语特别差,因而他每次比赛都要队友来给他翻译题目,然而现在队友回家了,他为了提高英语,决定看一篇很长的英文文章,文章有N个单词(0<N<=50000),但是他的词汇量只有M个单词(0<M<=5000)。在看文章的过程中,如果遇到他不会的单词,那么他就会去查字典,查过的单词他会了,那么以后遇到就不用再查了。现在给出文章和Xianbin5已经掌握的单词。让求他最小要查字典的次数。Input含多组样例(小于5组),每组样例为:首先给出N和M,用空格分开。然后给出一行英文其中包含N个单词, 阅读全文
posted @ 2012-07-23 18:51 zrq495 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 相同的代码用C就TLE,用C++就AC了..=_=///代码: 1 #include<stdio.h> 2 #include<math.h> 3 4 int main() 5 { 6 long long n; 7 double p; 8 while(scanf("%lld%lf", &n, &p)==2) 9 {10 printf("%.lf\n", pow(p, 1.0/n));11 }12 return 0;13 } 阅读全文
posted @ 2012-07-22 20:44 zrq495 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 不只是堆排序,其他排序也能过,很水的题,拿来练习堆排序的。代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int a[1000002]; 5 6 void heapadjust(int *a, int k, int n) 7 { 8 int i, j; 9 i=k;10 j=2*i;11 a[0]=a[i];12 while(j<=n)13 {14 if ((j<n) && a[j]>a[j+1])15 j++;16 if (a[0]>a[j])17 {... 阅读全文
posted @ 2012-07-21 19:01 zrq495 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 开始用字符串TLE,后来改成整数AC。先排序,再计数。代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 5 typedef struct 6 { 7 int num; 8 int count; 9 }node;10 11 int cmp(const void *a, const void *b)12 {13 node *pa=(node *)a;14 node *pb=(node *)b;15 return pa->num-pb->num;16 }17 18 i 阅读全文
posted @ 2012-07-18 11:37 zrq495 阅读(242) 评论(0) 推荐(0) 编辑
摘要: 题意:给出一些单词,以#结束,判断这些单词是否是ananagram。如果是按字典序输出。思路:每个大写字母变成小写,把单词中的字母按字典序排,再把单词按字典序排序,然后判断。最后输出没有改变的单词。 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 5 typedef struct 6 { 7 char s1[90]; //存放最初的单词。 8 char s2[90]; //存放小写排序后的单词。 9 int flag; //标记是否ananagram。10 }word... 阅读全文
posted @ 2012-07-17 16:32 zrq495 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 题意:求每一颗树距其他树最近的距离,如果小于10,那么相对应的距离点+1,输出距离为0,1,2,3,4,5,6,7,8,9的点的个数。用两个for循环遍历。代码如下: 1 #include<stdio.h> 2 #include<math.h> 3 4 typedef struct 5 { 6 int l, w, h; 7 }node; 8 9 int dis(node a, node b)10 {11 return (int)(sqrt( (double)((a.l-b.l)*(a.l-b.l)+(a.h-b.h)*(a.h-b.h) + (a.w-b.w)*(a.w 阅读全文
posted @ 2012-07-17 10:21 zrq495 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 判断给出的两数字及其和或积是否在int范围内。int最大为0x7fffffff。数组存放数字,在比较。代码如下: 1 #include<stdio.h> 2 #include<string.h> 3 4 char s[2000], a[2000], b[2000], op[2]; 5 int A[2000], B[2000], S[2000]; 6 7 void judge() 8 { 9 long long a1, b1, s1;10 sscanf(a, "%lld", &a1);11 sscanf(b, "%lld", 阅读全文
posted @ 2012-06-17 20:01 zrq495 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 大数乘法。代码如下: 1 #include<stdio.h> 2 #include<string.h> 3 4 void func(char a[]) 5 { 6 int i, len=strlen(a); 7 char t; 8 for (i=0; i<len/2; i++) 9 {10 t=a[i];11 a[i]=a[len-i-1];12 a[len-i-1]=t;13 }14 }15 16 int main()17 {18 int alen, blen, s, len, i, j;19 ... 阅读全文
posted @ 2012-06-16 00:29 zrq495 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 现象:机器双系统(Windows + Linux)使用GRUB作为bootloader在Windows下使用分区工具将Linux干掉重启计算机之后提示:GRUB-error: no such partitiongrub rescue \>以下是solution原文:GRUB- error: no such partition grub rescueThis was displayed on mine screen each time i restart mine computer. This happened with me after i deleted the ubuntu grub 阅读全文
posted @ 2012-06-14 22:30 zrq495 阅读(339) 评论(0) 推荐(0) 编辑
摘要: 查找、替换。发现一个很好用的函数,strstr().包含文件:string.h 函数名: strstr 函数原型:extern char *strstr(char *str1, char *str2); 功能:找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。 返回值:返回该位置的指针,如找不到,返回空指针。代码如下: 1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 int T, i, l; 7 char st1[50][85], st2[50][85]... 阅读全文
posted @ 2012-06-03 19:00 zrq495 阅读(161) 评论(0) 推荐(0) 编辑