??xml version="1.0" encoding="utf-8" standalone="yes"?>婷婷久久综合九色综合98,欧美成人免费观看久久,久久久久亚洲精品天堂久久久久久
http://www.shnenglu.com/meglory/category/13415.htmlcoding for life zh-cn Tue, 26 Apr 2011 16:22:42 GMT Tue, 26 Apr 2011 16:22:42 GMT 60 UVA 10815 http://www.shnenglu.com/meglory/archive/2011/04/03/143349.htmlmeglory meglory Sun, 03 Apr 2011 09:05:00 GMT http://www.shnenglu.com/meglory/archive/2011/04/03/143349.html http://www.shnenglu.com/meglory/comments/143349.html http://www.shnenglu.com/meglory/archive/2011/04/03/143349.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/143349.html http://www.shnenglu.com/meglory/services/trackbacks/143349.html I hate this type of problems... The key to this problem is the definition of a "word": a word is defined as a consecutive sequence of alphabets, in upper and/or lower case so, "won't" consists of two words, "won" and "t"......
]]> UVA 10878 http://www.shnenglu.com/meglory/archive/2011/03/24/142673.htmlmeglory meglory Thu, 24 Mar 2011 13:11:00 GMT http://www.shnenglu.com/meglory/archive/2011/03/24/142673.html http://www.shnenglu.com/meglory/comments/142673.html http://www.shnenglu.com/meglory/archive/2011/03/24/142673.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/142673.html http://www.shnenglu.com/meglory/services/trackbacks/142673.html 看到|上一个代码挺有意思的Q要我肯定写不了q么z。exp的用很_N?br> 原文Q?a href="http://www.shnenglu.com/syhd142/articles/130347.html">http://www.shnenglu.com/syhd142/articles/130347.html
1 #include < stdio.h > 2 #include < string .h > 3 4 #define N 20 5 6 const int exp[ 11 ] = { 0 , 128 , 64 , 32 , 16 , 8 , 0 , 4 , 2 , 1 }; 7 8 int main() 9 { 10 // freopen("out.txt", "w", stdout); 11 char data[N]; 12 while (gets(data)) 13 { 14 int sum = 0 ; 15 int l = strlen(data); 16 if (data[ 0 ] != ' | ' ) continue ; 17 for ( int i = 1 ; i < l - 1 ; i ++ ) 18 { 19 if (data[i] == ' . ' ) continue ; 20 if (data[i] == ' o ' ) sum += exp[i]; 21 } 22 printf( " %c " , sum); 23 } 24 return 0 ; 25 }
]]>UVA 10010 http://www.shnenglu.com/meglory/archive/2011/03/15/141922.htmlmeglory meglory Tue, 15 Mar 2011 15:16:00 GMT http://www.shnenglu.com/meglory/archive/2011/03/15/141922.html http://www.shnenglu.com/meglory/comments/141922.html http://www.shnenglu.com/meglory/archive/2011/03/15/141922.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/141922.html http://www.shnenglu.com/meglory/services/trackbacks/141922.html I learned that devising and testing program on a paper is quite effective. It's easier to edit and modify. Once you've finished coding, it's harder to modify your program. And devising at least several test cases before submitting your program. It's quite often that the Sample is somewhat misleading, there used to be long way between YES and merely making your program pass the Sample test. Most importantly, I can feel some improvement on my coding skills no matter how easy the problem I'm trying to solve seems to be. Just write your code, once day you will feel the improvements. ]]>UVA 401 http://www.shnenglu.com/meglory/archive/2011/03/14/141829.htmlmeglory meglory Mon, 14 Mar 2011 15:08:00 GMT http://www.shnenglu.com/meglory/archive/2011/03/14/141829.html http://www.shnenglu.com/meglory/comments/141829.html http://www.shnenglu.com/meglory/archive/2011/03/14/141829.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/141829.html http://www.shnenglu.com/meglory/services/trackbacks/141829.html q个题目׃一些时_(d)ȝ一下因Z面两个原因:(x) 1. q是读题的问题?/strong>题目有两个地Ҏ(gu)有注意到Qa.每个输出后面必须在输Z个空行;b. 题目关于0(zero)和O(letter)的问题我完全没有看懂去写代码了?br> 为啥L出现读题的问题呢Qȝ一条还是自己太急于d代码了,不愿意把镉K的说明读仔细。其实你在读题目时候因为几U钟的疏忽可能在最后调式代码的时候要花去几个时的时_(d)得不偿失啊。切记切记?br> 2.代码?fn)惯?我的一处出问题的代?while(s[i++]==t[j--] && j>=i) Q乍一看这么代码没啥问题,q省了@环里面的代码。但是,在同一行上面同时用i++和i是非常差的代码习(fn)惯,而这个坏?fn)惯C我这里就成了一个bug?/p>
]]> UVA 457 | 什么是Core DumpQ?/title> http://www.shnenglu.com/meglory/archive/2011/03/14/141755.htmlmeglory meglory Mon, 14 Mar 2011 00:24:00 GMT http://www.shnenglu.com/meglory/archive/2011/03/14/141755.html http://www.shnenglu.com/meglory/comments/141755.html http://www.shnenglu.com/meglory/archive/2011/03/14/141755.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/141755.html http://www.shnenglu.com/meglory/services/trackbacks/141755.html UVA457是个水题Q但是我q是到了一些小问题?br> 1.开了一个state[50][42]数组在main函数里面Q结果提交之后发现runtime errorQ觉着是堆栈溢Z。突然想h50*42>2000Q这U数l一定是开在main外面的,不然必然堆栈溢出?br>2.是读题不仔细Q当成了多重输入Q搞了一个while(scanf(...))Q结果超时了。第一ơ在UVA OJ上面时?br> 但是q篇文章重点不是讲这个,而是讲我在运行过E中l常遇到的core dumped现象。我在网上找C点资料,贴在下面Q?br> 原帖Q?a >http://blogold.chinaunix.net/u3/98822/showart_2093542.html什么是Core Dump? Core的意思是内存, Dump的意思是扔出? 堆出? 开发和使用UnixE序? 有时E序莫名其妙的down? 却没有Q何的提示(有时候会(x)提示core dumped). q时候可以查看一下有没有形如core.q程L(fng)文g生成, q个文g便是操作pȝ把程序down掉时的内存内Ҏ(gu)出来生成? 它可以做试程序的参? core dump又叫核心转储, 当程序运行过E中发生异常, E序异常退出时, 由操作系l把E序当前的内存状况存储在一个core文g? 叫core dump.如何使用core文g? gdb -c core文g路径 [应用E序的\径] q去后输入where回R, 可以显C程序在哪一行当掉的, 在哪个函C.Z么没有core文g生成? 有时候程序down? 但是core文g却没有生? core文g的生成跟你当前系l的环境讄有关p? 可以用下面的语句讄一? 然后再运行程序便成生成core文g. ulimit -c unlimited ?span style="TEXT-DECORATION: underline">没有扑ֈcore文gQ我们改改ulimit的设|,让它产生?024是随便取的,要是core文g大于1024个块Q就产生不出来了。)(j)$ ulimit -c 1024 Q{者注: 使用-c unlimited不限制core文g大小 ?br> core文g生成的位|一般于q行E序的\径相? 文g名一般ؓ(f)core.q程?br> 4. 用gdb查看core文g: 下面我们可以在发生运行时信号引v的错误时发生core dump? 发生core dump之后, 用gdbq行查看core文g的内? 以定位文件中引发core dump的行.gdb [exec file] [core file] ?gdb ./test test.core 在进入gdb? 用bt命o(h)查看backtrace以检查发生程序运行到哪里, 来定位core dump的文?>? ===========================================================================
造成E序core dump的原因很多,q里Ҏ(gu)以往的经验ȝ一下:(x)
1 内存讉K界
a) ׃使用错误的下标,D数组讉K界
b) 搜烦(ch)字符串时Q依靠字W串l束W来判断字符串是否结束,但是字符串没有正常的使用l束W?/p>
c) 使用strcpy, strcat, sprintf, strcmp, strcasecmp{字W串操作函数Q将目标字符串读/写爆。应该用strncpy, strlcpy, strncat, strlcat, snprintf, strncmp, strncasecmp{函数防止读写越界?/p>
2 多线E程序用了U程不安全的函数?/p>
应该使用下面q些可重入的函数Q尤其注意红色标C出来的函数Q它们很Ҏ(gu)被用错:(x)
asctime_r(3c) gethostbyname_r(3n) getservbyname_r(3n) ctermid_r(3s) gethostent_r(3n) getservbyport_r(3n) ctime_r(3c) getlogin_r(3c) getservent_r(3n) fgetgrent_r(3c) getnetbyaddr_r(3n) getspent_r(3c) fgetpwent_r(3c) getnetbyname_r(3n) getspnam_r(3c) fgetspent_r(3c) getnetent_r(3n) gmtime_r(3c) gamma_r(3m) getnetgrent_r(3n) lgamma_r(3m) getauclassent_r(3) getprotobyname_r(3n) localtime_r(3c) getauclassnam_r(3) etprotobynumber_r(3n) nis_sperror_r(3n) getauevent_r(3) getprotoent_r(3n) rand_r(3c) getauevnam_r(3) getpwent_r(3c) readdir_r(3c) getauevnum_r(3) getpwnam_r(3c) strtok_r(3c) getgrent_r(3c) getpwuid_r(3c) tmpnam_r(3s) getgrgid_r(3c) getrpcbyname_r(3n) ttyname_r(3c) getgrnam_r(3c) getrpcbynumber_r(3n) gethostbyaddr_r(3n) getrpcent_r(3n)
3 多线E读写的数据未加锁保护?/p>
对于?x)被多个U程同时讉K的全局数据Q应该注意加锁保护,否则很容易造成core dump
4 非法指针
a) 使用I指?/p>
b) 随意使用指针转换。一个指向一D内存的指针Q除非确定这D内存原先就分配为某U结构或cdQ或者这U结构或cd的数l,否则不要它转换U结构或cd的指针,而应该将q段内存拯C个这U结构或cd中,再访问这个结构或cd。这是因为如果这D内存的开始地址不是按照q种l构或类型对齐的Q那么访问它时就很容易因为bus error而core dump.
5 堆栈溢出
不要使用大的局部变量(因ؓ(f)局部变量都分配在栈上)(j)Q这样容易造成堆栈溢出Q破坏系l的栈和堆结构,D出现莫名其妙的错误? ------- 我自q序core dumped是因ؓ(f)W?个原因,堆栈溢出。我的局部数l开的过大,而局部变量分配在栈上Q导致堆栈溢出?/p>
]]>UVA 489 http://www.shnenglu.com/meglory/archive/2011/03/12/141679.htmlmeglory meglory Sat, 12 Mar 2011 15:07:00 GMT http://www.shnenglu.com/meglory/archive/2011/03/12/141679.html http://www.shnenglu.com/meglory/comments/141679.html http://www.shnenglu.com/meglory/archive/2011/03/12/141679.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/141679.html http://www.shnenglu.com/meglory/services/trackbacks/141679.html 发帖前再ơ抱怨一下C++博客不支持最新的Firefox发帖的情况,让我辛辛苦苦码的字又找不C?br> q个题目折腾了我一D|_(d)是因Z面的情况自己没有考虑Q?br> 被猜的字符串ؓ(f)Qab 1. 猜测abcdefghijklmnQ结果ؓ(f)win 2.猜测cdefghijklmnabQ结果ؓ(f)lose q就要求处理的时候, a. 如果被猜串中所有字W都被猜中,应即时停止统计,跛_循环Q?br>b.如果错误猜测的次数已l到达了7ơ,应该x停止l计Q蟩出@环?br> 我之前的E序没有对上q情况处理,所以导?情况输出p|Q因为我把后面的错误ơ数都统计完之后Q才跛_循环看是否错误超q?ơ,q么当然就是lose了;而对?情况Q因为确实猜CabQ在里面把字W统计之后再跛_来看被猜穿Q反而是所有字W到猜到了,所以win了?br> 被折腾了一下还是挺高兴Q即时水题也有需要留心的地方。}记?br>
]]> UVA 445 http://www.shnenglu.com/meglory/archive/2011/03/07/141315.htmlmeglory meglory Mon, 07 Mar 2011 15:23:00 GMT http://www.shnenglu.com/meglory/archive/2011/03/07/141315.html http://www.shnenglu.com/meglory/comments/141315.html http://www.shnenglu.com/meglory/archive/2011/03/07/141315.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/141315.html http://www.shnenglu.com/meglory/services/trackbacks/141315.html 考察 1a3x3 1a3a ok?/p>
]]> L自己的做题习(fn)??随感 http://www.shnenglu.com/meglory/archive/2010/07/16/120596.htmlmeglory meglory Fri, 16 Jul 2010 15:07:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/16/120596.html http://www.shnenglu.com/meglory/comments/120596.html http://www.shnenglu.com/meglory/archive/2010/07/16/120596.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/120596.html http://www.shnenglu.com/meglory/services/trackbacks/120596.html 2010-7-16 -------------------- 在设计算法的时候,拿出一张纸自己列出来思\Qƈ且实现算法。如果只是一味的I想Ҏ(gu)作无用功Q很久想不明白的东西M囑ֈ表就可能清楚了。实现完成之后,我之前的?fn)惯是过了Sample立马SubmitQ完全就是撞q气。这个时候应该l在U怸跑一遍自qE序Q看是否每个边界条g都按照预期达CQ程序是不是C之前预想的\径?/span> ]]>刷题W一?/title> http://www.shnenglu.com/meglory/archive/2010/07/16/120594.htmlmeglory meglory Fri, 16 Jul 2010 15:01:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/16/120594.html http://www.shnenglu.com/meglory/comments/120594.html http://www.shnenglu.com/meglory/archive/2010/07/16/120594.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/120594.html http://www.shnenglu.com/meglory/services/trackbacks/120594.html uva 490 转动字符Ԍ(x)Linux下面的Ctrl-D和W(xu)indows下面的Ctrl-Z一样可以模拟EOF. ]]> 《算法竞赛入门经典》学?fn)笔讎ͼ枚D http://www.shnenglu.com/meglory/archive/2010/07/15/120483.htmlmeglory meglory Thu, 15 Jul 2010 14:02:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/15/120483.html http://www.shnenglu.com/meglory/comments/120483.html http://www.shnenglu.com/meglory/archive/2010/07/15/120483.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/120483.html http://www.shnenglu.com/meglory/services/trackbacks/120483.html 除法 输入正整数n,按从到大的序输出所有Ş?abcde/fghij=n的表辑ּQ其中a~j恰好为数?~9的一个排列,2<=n<=79?br>样例输入Q?br>62 样例输出Q?br>79546/01283=62 94736/01528=62 如何解决q个问题Q?br> 2010-7-16更新 上面的问题让我一下子惛_了如何求一个序列的全排列的问题Q于是顺着q个思\摸烦(ch)了一下。GoogleC一个算法?br>递归
例说明如何编写全排列的递归法?br>1、首先看最后两个数4, 5?它们的全排列? 5? 4, 即以4开头的5的全排列和以5开头的4的全排列。由于一个数的全排列是其本w,从而得C上结果?br>2、再看后三个?, 4, 5。它们的全排列ؓ(f)3 4 5? 5 4?4 3 5?4 5 3?5 3 4?5 4 3 六组数?br>即以3开头的?,5的全排列的组合、以4开头的?,5的全排列的组合和?开头的?,4的全排列的组? 从而可以推断,设一l数p = {r1, r2, r3, ... ,rn}, 全排列ؓ(f)perm(p)Qpn = p - {rn}?br>因此perm(p) = r1perm(p1), r2perm(p2), r3perm(p3), ... , rnperm(pn)。当n = 1时perm(p} = r1?br>Z更容易理解,整l数中的所有的数分别与W一个数交换Q这样就L在处理后n-1个数的全排列?/span> ]]> 素数{选法实现的问?/title> http://www.shnenglu.com/meglory/archive/2010/07/14/120320.htmlmeglory meglory Wed, 14 Jul 2010 05:22:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/14/120320.html http://www.shnenglu.com/meglory/comments/120320.html http://www.shnenglu.com/meglory/archive/2010/07/14/120320.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/120320.html http://www.shnenglu.com/meglory/services/trackbacks/120320.html 我实C一个原生的版本Q后来在Wikipedia看到Ƨ拉的优化版本,但是不大知道如何实现?br>原来的版本是直接判断是否是素敎ͼ所以空间占的比较少Q时间比较多。打表法以后Q应该是I间换时间的办法Q但是ؓ(f)啥时间和I间都变大了呢? 应该是我实现的有问题Q今天思考一下?br>
7152474
meGLORY
3006
Accepted
4056K
641MS
C
551B
2010-07-14 11:35:03
7150446
meGLORY
3006
Accepted
156K
250MS
C
405B
2010-07-14 00:15:01
大概思考了一下,加了几个判断语句Q时间成功的降到?00多一点了Q内存还?056K.
]]> POJ 3006 Dirichlet's Theorem on Arithmetic Progressions http://www.shnenglu.com/meglory/archive/2010/07/12/120116.htmlmeglory meglory Mon, 12 Jul 2010 05:07:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/12/120116.html http://www.shnenglu.com/meglory/comments/120116.html http://www.shnenglu.com/meglory/archive/2010/07/12/120116.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/120116.html http://www.shnenglu.com/meglory/services/trackbacks/120116.html q两天都是水题,没有什么想法而言Q就是ؓ(f)了熟(zhn)一下感觉。我又给互联|上增加了不垃圾日志?br>昨晚Z点突发事Ӟ原定的写E序事g被用来处理事情了。不q后来我倒是有点x白了Q题目只是很一Ҏ(gu)间在看题目,很忙的时候可以先花几分钟把题目弄明白了,然后在去忙别的事情,q种件的I隙q能想一x\。不知POJ有什么办法可以把题目扚w导出的,我就不用天天费劲上网读题目了Q在单位也能抽空瞅两眹{?br> 我坚持两件事情:(x)1。决不直接脓(chung)题目 ?/span>代码 2。每天都写题?br> POJ 3006 计划打个表,然后直接搞,看了一下数据很,应该没有什么问题?br> 在这里顺侉K一下素数筛选法?br>以下内容来自Wikipedia:
To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method:
Create a list of consecutive integers from two to n : (2, 3, 4, ..., n ).
Initially, let p equal 2, the first prime number.
Strike from the list all multiples of p less than or equal to n . (2p, 3p, 4p, etc. )
Find the first number remaining on the list after p (this number is the next prime); replace p with this number.
Repeat steps 3 and 4 until p 2 is greater than n .
All the remaining numbers in the list are prime
后来Q欧拉同学提Z另外一个办法,让每个数只要标记一ơ就ok
A) Start with all the natural numbers except '1' which is not a prime: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ... ^ B) The leftmost number is prime. Multiply each number in the list by this prime and then discard the products: (4 6 8 10 12 14 16 18 20 22 24 26 28 30 ... ) These are removed: 4 6 8 10 12 14 16 18 20 22 24 26 28 30 These are left: 2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... ^ C) The number after the previous prime is also a prime. Multiply by it each number in the new list starting from this prime and then discard the products: (9 15 21 27 33 39 45 51 57 63 69 75 81 87 ...) These are removed: 9 15 21 27 These are left: 2 3 5 7 11 13 17 19 23 25 29 ... ^
================================================= 2010-7-13 23:47 拆掉了自q惠普V3159W记本,心情一片大好,竟然装上以后q行正常了。出来Q迟早要q,之前一直对于拆机器的事情不感兴,现在可真是被逼得?br>我终于可以去中关村赚取那90块的拆机费了: ) PS:今天中午修好了屋子里面的抽水马桶Q心情一片大好?br> ]]> POJ 1153 Integer Inquiry http://www.shnenglu.com/meglory/archive/2010/07/11/120056.htmlmeglory meglory Sat, 10 Jul 2010 17:47:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/11/120056.html http://www.shnenglu.com/meglory/comments/120056.html http://www.shnenglu.com/meglory/archive/2010/07/11/120056.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/120056.html http://www.shnenglu.com/meglory/services/trackbacks/120056.html 非常单的题目Q没有方法可a?br>1。之前忘记拿chard的,所以直接把int和char相加所以结果一直很奇怪?br>2。题目的数字?x)出C0开头的非零数字Q这个当初读题完全没有想到。但是看到discuss之后回去读题Q发现题目确实题目没有说不可以。这个还是自己没有考虑周全?br> ]]> POJ 2262 Goldbach's Conjecture http://www.shnenglu.com/meglory/archive/2010/07/09/119806.htmlmeglory meglory Thu, 08 Jul 2010 16:26:00 GMT http://www.shnenglu.com/meglory/archive/2010/07/09/119806.html http://www.shnenglu.com/meglory/comments/119806.html http://www.shnenglu.com/meglory/archive/2010/07/09/119806.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/119806.html http://www.shnenglu.com/meglory/services/trackbacks/119806.html 1.WA数次Q因界的问题Q把2也当成候选数了,没有留心two odd primes. 2.gcc~译math.hӞ需?lm. 3.如何从vim里面把代码拷出来提交到POJ的那个框框里面?我搞了半天没有解?br> 附:(x)
gcc -l参数
-l参数是用来指定E序要链接的库,-l参数紧接着是库名Q那么库名跟真正的库文g名有什么关pdQ就拿数学库来说Q他的库名是mQ他的库文g名是libm.soQ很Ҏ(gu)看出Q把库文件名的头lib和尾.soL是库名?/p>
]]>UVA 494的读题错?/title> http://www.shnenglu.com/meglory/archive/2010/04/04/111600.htmlmeglory meglory Sun, 04 Apr 2010 10:21:00 GMT http://www.shnenglu.com/meglory/archive/2010/04/04/111600.html http://www.shnenglu.com/meglory/comments/111600.html http://www.shnenglu.com/meglory/archive/2010/04/04/111600.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/111600.html http://www.shnenglu.com/meglory/services/trackbacks/111600.html
q道题是很简单的一个题目。我的题目理解稍微有炚w题,所以花了一些时间才搞清楚?/p>
q碰巧发C一个讨论uva的论坛,很好很强大。就是里面一位老大的一句话让我豁然开朗?br>关键在于题目里面关于word的定义?/p>
A “word” is defined as a consecutive sequence of letters (upper and/or lower case).
Your program should output a word count for each line of input. Each word count should be printed on a separate line.
一开始我以ؓ(f)直接判断scanf(“%s”,s)的次数就ok。后来不停地wa。发现题目里面怎么qdid!也算作一个单词,不是q箋的字母吗Q?
I did! I did! I did taw a putty tat.
比如q个字符串用我的理解是应该是八个word。后来想刎ͼ是一开始用d字符传的思维D了我的错误。这个题目是一个字W一个字W的处理的,q不是一下读q来一个字W串然后一个个的判断?/p>
惛_q里Q我豁然开朗?/p>
]]> 《算法竞赛入门经典?MW记-蛇Ş填数 http://www.shnenglu.com/meglory/archive/2010/03/29/110937.htmlmeglory meglory Mon, 29 Mar 2010 14:53:00 GMT http://www.shnenglu.com/meglory/archive/2010/03/29/110937.html http://www.shnenglu.com/meglory/comments/110937.html http://www.shnenglu.com/meglory/archive/2010/03/29/110937.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/110937.html http://www.shnenglu.com/meglory/services/trackbacks/110937.html 一开始在安面有了一Ҏ(gu)\Q用两重循环。后来真正开始在U怸写代码的时候发现只要一重@环即可?nbsp;
#include < stdio.h > int main() { int a[ 10 ][ 10 ]; int dx[] = { 1 , 0 , - 1 , 0 }; int dy[] = { 0 , - 1 , 0 , 1 }; int value = 1 ; int i,j,n,x,y; scanf( " %d " , & n); for (i = 1 ;i <= n;i ++ ) for (j = 1 ;j <= n;j ++ ) a[i][j] = 0 ; // 初始位置?1,n),初始gؓ(f)1 x = 1 ; y = n; i = 0 ; a[x][y] = value ++ ; // 循环l束的条件ؓ(f)n*n个值已l赋?/span> while (value <= n * n) { // 按照当前的方向进行探?/span> x += dx[i]; y += dy[i]; // 如果W合条gQ赋?/span> if (x >= 1 && x <= n && y >= 1 && y <= n && a[x][y] == 0 ) a[x][y] = value ++ ; // 如果不符合条Ӟ把坐标退回,方向q行逆时针旋?/span> else { x-= dx[i]; y -= dy[i]; i = (i + 1 ) % 4 ; } printf( " \nvalue=%d\n " ,value); } for (i = 1 ;i <= n;i ++ ) { for (j = 1 ;j <= n;j ++ ) printf( " %d " ,a[i][j]); printf( " \n " ); } return 0 ; }
后来看到书上的sample代码Q我觉着我的代码昄要好很多:-)
]]> 《算法竞赛入门经典?MW记-排列&分数化小?/title> http://www.shnenglu.com/meglory/archive/2010/03/29/110938.htmlmeglory meglory Mon, 29 Mar 2010 14:53:00 GMT http://www.shnenglu.com/meglory/archive/2010/03/29/110938.html http://www.shnenglu.com/meglory/comments/110938.html http://www.shnenglu.com/meglory/archive/2010/03/29/110938.html#Feedback 0 http://www.shnenglu.com/meglory/comments/commentRss/110938.html http://www.shnenglu.com/meglory/services/trackbacks/110938.html ?,2,3,···,9 l成 3 个三位数 abc , def ?/span>ghi, 每个数字恰好使用一ơ,要求abc:def:ghi=1:2:3。输出所有解?/span> 题目特别写出了提C:(x)不必太动脑筋?其实q句话让我现在都不清楚我的解法是不是W合要求......)
1 #include < stdio.h > 2 #include < stdlib.h > 3 int main() 4 { 5 int num; 6 char chr; 7 char a[ 10 ]; 8 char temp[ 3 ]; 9 char pos; 10 // num*3<=987 所?num<=329 11 for (num = 123 ;num <= 329 ;num ++ ) 12 { 13 itoa(num,temp, 10 ); 14 strcpy(a,temp); 15 itoa(num * 2 ,temp, 10 ); 16 strcat(a,temp); 17 itoa(num * 3 ,temp, 10 ); 18 strcat(a,temp); // a保存了num以及(qing)num*2和num*3l成的字W串 19 20 for (chr = ' 1 ' ;chr <= ' 9 ' && (pos = strchr(a,chr)) != NULL;chr ++ ) 21 ; 22 if (pos != NULL) 23 printf( " %d:%d:%d=1:2:3\n " ,num,num * 2 ,num * 3 ); 24 } 25 return 0 ; 26 } 27
今天l箋d了分数化数题目Q感觉挺单的一个问题。实际藏着一个我q不知道的printf妙用?/span>
输入正整数a,b,c,输出a/b的小数Ş式,_到小数点后c位。a,b<=10^6,c<=100.例如a=1,b=6,c=4时应输出0.1667.
printf的特D用法,对于m.n的格式可以用如下Ҏ(gu)表示
char ch[20]; printf("%*.*s\n",m,n,ch); 前边?定义的是ȝ宽度Q后边的定义的是输出的个数。分别对应外面的参数m和n ?q种Ҏ(gu)的好处是可以在语句之外对参数m和n赋|从而控制输出格式?/span> 1 #include < stdio.h > 2 int main() 3 { 4 int a,b,c; 5 scanf( " %d %d %d " , & a, & b, & c); 6 printf( " %.*lf " ,c,( double )a / b); 7 return 0 ; 8 }
]]>
ƷŮٸAVѾþ |
ƷۺϾþһ |
AVþ |
ŷҹƷþþþ |
þҹҹݺ2022 |
Ʒľþþ |
һɾþþƷۺ |
㽶þҹɫƷ |
þþƷĻþ |
Ʒ˾þ |
þ99Ʒ鶹ѿ |
Ʒþþþþ˳ |
þݺҹҹ2020츾 |
ŷҹAŴƬþ |
˾þþƷһ |
þ99ۺϾƷ |
ݺɫþþۺ |
þֻƷ99 |
Ʒݾþþþ |
97Ʒþ찴Ħ |
ƷþþþþóAV |
þþƷѲ |
AVþþþò |
ŷҹƷþ |
ľƷþþþùַ |
91Ʒ91þþþþ |
ۺϾþۺϼþ |
þþƷA㽶 |
ƷŮþþ |
þһ |
ɫվľþò |
պŷþþwwwۺ |
ŷպþAV |
avþþþþòվ
|
žžþ99ۺһ |
þ99ƷþþþþҰ |
鶹þ |
þþƷһۺ |
һaƬþëƬ |
Ļ˾Ʒþò
|
18պҹþó |