锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久天天躁狠狠躁夜夜2020老熟妇,囯产精品久久久久久久久蜜桃,久久国产精品-国产精品http://cppblog.com/sixleaves/category/20814.html閲嶅墤鏃犻攱 澶у閥涓嶅伐zh-cnMon, 13 Apr 2015 03:44:39 GMTMon, 13 Apr 2015 03:44:39 GMT60UVA11988 Broken KeyBoardhttp://www.shnenglu.com/sixleaves/archive/2015/04/12/210311.htmlswpswpSat, 11 Apr 2015 16:10:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/04/12/210311.htmlhttp://www.shnenglu.com/sixleaves/comments/210311.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/04/12/210311.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210311.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210311.html閾捐〃緙栫爜瑕佺悊娓呯粏鑺傛ф濊礬錛屾渶濂芥槸綆鍗曠殑鐢諱笅鍥撅紝姝e鏀歸鐨勯摼琛紝鏈川涓婃槸寰幆閾捐〃銆俵ast鎸囧悜鏈鍚庝竴涓妭鐐廣傚叾next鎸囬拡涓瀹氭寚鍚戝ご鑺傜偣銆傛垜浠妸s[0]褰撳仛澶磋妭鐐廣?br />
 1 
 2 #include <cstdio>
 3 #include <cstring>
 4 const int maxn = 100000 + 5;
 5 int last, cur, next[maxn];
 6 char s[maxn];
 7 int main() {
 8     
 9     while ( scanf("%s", s + 1) == 1) {
10         
11         int n = strlen(s + 1);
12         last = cur = 0;
13         next[0] = 0; // 澶寸粨鐐瑰垵濮嬪寲鎸囧悜鑷韓
14         
15         for (int i = 1; i <=n; i++) {
16             
17             char ch = s[i];
18             if ('[' == ch ) cur = 0;
19             else if (']' == ch) cur = last;
20             else {
21                 
22                 next[i] = next[cur];  // next[cur]涓哄綋鍓嶅厜鏍囩殑鍓嶄竴涓瓧絎︼紝鑰宯ext[i]灝辨槸褰撳墠鍏夋爣瑕佽緭鍏ョ殑瀛楃錛屾帴鐫錛屽厜鏍囪繕瑕佽煩鍒頒笅涓瓧絎︺傛墍浠ユ垜浠鎶婂綋鍓嶅瓧絎ext鎸囧悜鍏夋爣杈撳叆鐨勫瓧絎︺備篃灝辨槸next[cur] = i;浣嗚鍏堜繚瀛樺叾next鎸囬拡緇欒緭鍏ュ瓧絎︺傚叾next鎸囬拡鍏跺疄灝辨槸鐪熺浉澶寸粨鐐廣?/span>
23                 next[cur] = i;
24                 if (cur == last) last = i;
25                 cur = i; // 鎸囧悜涓嬩竴涓妭鐐?/span>
26             }
27             
28         }
29         
30         for (int i = next[0];i != 0; i = next[i]) {
31             printf("%c", s[i]);
32         }
33         puts("");
34     }
35     
36     return 0;
37 }

2015/4/12涓婂崍12:10:12


swp 2015-04-12 00:10 鍙戣〃璇勮
]]>
UVA442 Matrix Chain Multiplicationhttp://www.shnenglu.com/sixleaves/archive/2015/04/11/210305.htmlswpswpFri, 10 Apr 2015 18:33:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/04/11/210305.htmlhttp://www.shnenglu.com/sixleaves/comments/210305.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/04/11/210305.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210305.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210305.html 1 #include <cstdio>
 2 #include <iostream>
 3 #include <string>
 4 #include <stack>
 5 
 6 using namespace std;
 7 
 8 struct Matrix {
 9     int r,c;
10     Matrix(int a = 0, int b = 0) : r(a), c(b) {};
11 }m[26];
12 
13 stack<Matrix> s;
14 
15 int main()
16 {
17     
18     int n;
19     cin >> n;
20     for (int i = 0; i < n; i++) {
21         string name;
22         cin >> name;
23         int k = name[0] - 'A';
24         cin >> m[k].r >> m[k].c;
25         
26     }
27     
28     string expr;
29     while (cin >> expr) {
30         
31         int len = expr.size(); // 鑾峰彇瀛楃涓茬殑澶у皬錛屽洜涓鴻繖鏁翠釜瀛楃涓查兘娌℃湁絀烘牸
32         bool error = false;
33         int ans = 0;
34         for (int i = 0; i < len; i++) { // 寰幆鏁翠釜琛ㄨ揪寮忋佹濊礬鏄亣鍒板彸鎷彿灝卞嚭鏍堜袱涓狹atrix榪涜璁$畻錛岀畻瀹屽湪鍘嬪洖銆?br />35             // 鍏跺疄浣犲彲浠ュ彂鐜板甫鎷彿鐨勮〃杈懼紡鍗佸垎絎﹀悎鏍堬紝鑰屼笉浠呬粎鏄棰樼洰錛岄鍏堝乏鎷彿瓚婃繁
36             // 鍏惰綆楃殑鏈夊厛綰у埆瓚婇珮錛岃屽彸鎷彿鍙堝拰宸︽嫭鍙烽厤瀵癸紝濡傛灉鎴戜滑浠庡乏鍒板彸璇誨彇涓涓〃杈懼紡
37             // 姣忔涓閬囧埌鍙蟲嫭鍙鳳紝鍏跺墠闈㈠埌宸︽嫭鍙風殑閮ㄥ垎鑲畾灝辨槸榪欎釜琛ㄨ揪寮忔渶浼樺厛鐨勯儴鍒嗐?/span>
38             if (isalpha(expr[i])) { s.push(m[expr[i] - 'A']); }
39             else if (')' == expr[i]) {
40                 Matrix m2 = s.top(); s.pop();
41                 Matrix m1 = s.top(); s.pop();
42                 if (m1.c != m2.r) { error = truebreak; }
43                 ans += m1.r * m1.c * m2.c;
44                 s.push(Matrix(m1.r, m2.c));
45             }
46             
47         }
48         
49         if (error) printf("error\n"); else printf("%d\n", ans);
50         
51     }
52     
53     return 0;
54 }
55 

2015/4/10涓嬪崍6:32:37
By sixleaves

swp 2015-04-11 02:33 鍙戣〃璇勮
]]>
UVA514 Railshttp://www.shnenglu.com/sixleaves/archive/2015/03/30/210195.htmlswpswpMon, 30 Mar 2015 08:17:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/30/210195.htmlhttp://www.shnenglu.com/sixleaves/comments/210195.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/30/210195.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210195.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210195.html 閾佽建

PopPush鍩庡競鏈変竴搴ц憲鍚嶇殑鐏濺绔欍傝繖涓浗瀹跺埌澶勯兘鏄笜闄點傝岃繖涓伀杞︾珯鏄緩浜庝笂涓涓笘綰備笉騫哥殑鏄紝閭f椂鐨勮祫閲戞湁闄愩傛墍浠ュ彧鑳藉緩绔嬭搗涓鏉¤礬闈㈤搧杞ㄣ傝屼笖錛岃繖瀵艱嚧榪欎釜鐏濺绔欏湪鍚屼竴涓椂鍒誨彧鑳戒竴涓建閬撴姇鍏ヤ嬌鐢紝鍥犱負瀹冪己灝戠┖闂達紝涓ゅ垪鐏濺灝嗘棤璺彲璧般傚叿浣撶湅涓嬪浘銆?/strong>

褰撳湴鐨勬儻渚嬫槸姣忎竴鍒楃伀杞︿粠A鏂瑰悜椹跺悜B鏂瑰悜鏃跺欙紝浼氱敤鏌愮鏂瑰紡灝嗚濺鍘㈤噸緇勩傚亣璁劇伀杞﹀皢瑕佸埌杈続鏂瑰悜錛屾嫢鏈塏涓濺鍘?N<=1000),榪欎簺杞﹀帰鎸夌収閫掑欏哄簭鏍囪涓?鍒癗銆傝礋璐d粠緇勮濺鍘㈢殑棰嗗,蹇呴』鐭ラ亾鏄惁鑳戒粠緇勮濺鍘㈣瀹冮┒鍑築錛岃岃繖涓噸緇勭殑搴忓垪灝辨槸a1\a2\a3...aN.甯粍浠栧茍涓斿啓涓涓▼搴忔潵鍒ゆ柇鏄惁鍙兘鎸夌収鎵瑕佹眰鐨勮濺鍘㈤『搴忋備綘鍙互鍋囪錛屽崟涓殑杞﹀帰鍙互浠庡垪杞︿笂鍒嗙鍑烘潵錛屽湪浠栦滑榪涘叆绔欏彴涔嬪墠銆傚茍涓斾粬浠彲浠ヨ嚜鐢辯Щ鍔紝鐭ラ亾瀹冧滑涓婁簡B杞ㄩ亾銆備綘涔熷彲浠ュ亣璁懼湪浠繪剰鏃跺欑珯鍙板彲浠ユ斁涓嬫棤鏁扮殑杞﹀帰銆備絾鏄彧瑕佷竴涓濺鍘㈣繘鍏ョ珯鍙幫紝瀹冨氨涓嶈兘榪斿洖A杞ㄩ亾錛屽悓鏃跺鏋滃畠紱誨紑浜嗙珯鍙伴┒鍚態杞ㄩ亾錛屽畠灝變笉鑳借繑鍥炵珯鍙般?/strong>

杈撳叆錛?/strong>
榪欎釜杈撳叆鏂囦歡鐢卞涓鍧楃粍鎴愩傛瘡涓涓潡鎻忚堪鐨勬槸澶氫釜瑕佹眰鐨勯噸緇勮濺鍘㈢殑搴忓垪銆傚湪榪欐瘡涓潡涓殑絎竴琛屾槸涓涓暣鏁癗錛岃鐢ㄦ潵璇存槑涓婇潰姣忚鐨勮濺鍘釜鏁般傝繖涓揩鐨勬渶鍚庝竴琛屼粎浠呮槸涓涓暟瀛?瑕佹潵鏍囪璇ュ揩鐨勭粨鏉?/strong>
鏈鍚庝竴涓潡浠呬粎鏄竴涓?鐙崰涓琛屻?/strong>

杈撳嚭錛?/strong>
榪欎釜杈撳嚭鏂囦歡鍖呭惈澶氳錛岃繖浜涜鍜屾帓鍒楄濺鍘㈢殑琛屾暟涓涓瀵瑰簲銆傛棩榪囪鎺掑垪鍙錛屽垯杈撳嚭Yes錛屽惁鍒欒緭鍑篘o銆傚彟澶栧瓨鍦ㄤ竴涓┖琛屽湪姣忎釜鐩稿搴旂殑鍧楀悗闈€傝緭鍑烘枃浠朵腑涓嶅瓨鍦ㄤ簬鏈鍚庝竴涓粈涔堟暟鎹兘娌℃湁鐨勫搷搴旇緭鍑恒?/strong>

杈撳嚭
5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
0
0

Output
Yes
No

Yes

 1 /*
 2 鐢變簬station絎﹀悎鍚庤繘鍏堝嚭瑙勫垯錛屾墍浠ュ彲浠ョ敤涓涓猻tack<int>鏉ヨ〃紺簊tation銆?br /> 3 鐒跺悗閲囩敤妯℃嫙鐨勮鍒欐潵鍐欙紝鍥犱負榪涘叆station鏄寜鐓х紪鍙烽掑榪涘叆錛屾墍浠ュ彲浠ョ敤aId鍙橀噺琛ㄧず銆?br /> 4 鎺ヤ笅鏉ュ氨鏄ā鎷熸椂鍊欏簲璇ユ敞鎰忕殑鏉′歡錛屾垜浠煡閬撴湁浠ヤ笅涓ょ鎯呭喌錛屼竴縐嶆槸涓榪涙潵station錛屽氨鍑簊tation
 5 涔熷氨鏄?nbsp;aId == coaches[lenB]; 涓縐嶆槸榪涙潵鏃惰繕涓嶅嚭绔欙紝閭d箞榪欐椂鍊欏氨瑕乻.push(aId),浣嗘槸榪欎竴縐嶇殑鏉′歡鍛紵
 6 鎴戜滑濡傛灉鍙互鎺掗櫎鎺夌涓縐嶏紝閭d箞鏃犻潪灝辨槸絎簩縐嶄簡銆備絾鏄垜浠鐭ラ亾錛屽湪榪涚珯涔嬪墠錛屽鏋滅珯鍙伴噷鏈夎濺瀹冩槸鍙互鍏堝嚭绔欑殑
 7 錛岃繖縐嶇姸鎬佸氨鏉′歡灝辨槸 !s.empty() && s.top() == coaches[lenB].鎵浠ュ彧瑕佹寜鐓ч『搴忓垽鏂繖鍑犱釜鏉′歡
 8 灝卞彲浠ュ啓鍑鴻繖涓ā鎷熺▼搴忎簡銆?br /> 9 
10 
11 鎬葷粨錛?br />12 瑙e喅闂鐨勫叧閿偣錛屽湪浜庢瀯寤洪棶棰樼殑妯″瀷銆佸ぇ閮ㄥ垎閮芥槸鍙互鐢ㄧ幇鏈夌殑鍩虹鏁版嵁緇撴瀯銆傛瀯閫犲畬瀵瑰簲鐨勬暟鎹粨鏋勶紝鐗瑰埆鏄浜庢ā鎷熼
13 鏃犻潪灝辨槸鐘舵佽鐨勮漿縐誨鐞嗭紝榪欐槸灝辮鍦ㄥ熀浜庢ā鍨嬬殑鍩虹涓娿佸厛鍐欏嚭鏄犲皠鍒頒釜涓姸鎬佺殑鍞竴鏉′歡錛岀劧鍚庢寜鐓ч棶棰橀昏緫涓涓鍏堝悗鍒ゆ柇
14 鍗沖彲銆?br />15 */
16 #include <iostream>
17 #include <stack>
18 
19 using namespace std;
20 const int len = 1024;
21 int coaches[len];
22 
23 int main() {
24 
25     int n;
26     while (cin >> n, n) { 
27         stack<int> s;
28         // read the required permutaion
29 
30         while (    cin >> coaches[0], coaches[0]) {
31 
32             for (int i = 1; i < n; i++) {
33                 cin >> coaches[i];
34             }
35             int lenB = 0, aId = 1;
36             bool ok = true;
37             while (lenB < n) {
38 
39                 if (aId == coaches[lenB]) {  aId++; lenB++; }
40                 else if(!s.empty() && s.top() == coaches[lenB]) { s.pop(); lenB++; }
41                 else if(aId <= n) s.push(aId++);
42                 else { ok = falsebreak; }
43 
44             }
45 
46             cout << (ok ? "Yes" : "No") << endl;
47         }
48         cout << endl;
49     }
50     
51     return 0;
52 }
2015/3/30涓嬪崍3:03:52


swp 2015-03-30 16:17 鍙戣〃璇勮
]]>
UVA 400 Unix ls by sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/25/210160.htmlswpswpWed, 25 Mar 2015 06:32:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/25/210160.htmlhttp://www.shnenglu.com/sixleaves/comments/210160.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/25/210160.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210160.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210160.html涓昏瀛︿範鐨勬妧鑳借鐐瑰氨鏄浣曠敤鍋忕Щ浣嶇Щ娉曟潵鎸夊垪杈撳嚭銆傚鏋滀竴涓煩闃祅琛宮鍒楋紝瑕佹寜鐓у垪杈撳嚭銆備絾鏄垜浠煡閬擄紝緙栫▼鏃跺欙紝鍙兘鏄痜or(琛?鍦ㄥ垪銆傛墍浠ュ繀欏昏鏈変竴涓亸縐婚噺鏉ヨ綆楄繖縐嶅亸縐誨叧緋匯倄 = rows * c + r;

 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <cmath>
 6 
 7 using namespace std;
 8 
 9 vector<string> words;
10 void print(const string &s, int len, char extra);
11 int main() {
12     
13     
14     int n;
15     string w;
16     
17     while (cin >> n) {
18         
19         int max = 0;
20         words.clear();
21         for (int i = 0; i < n; i++) {
22             cin >> w;
23             string::size_type str_size = w.size();
24             if (str_size > max) max = str_size;
25             words.push_back(w);
26         }
27         int cols = (60 - max) / (max + 2) + 1;
28         int rows = ceil(double(n) / cols);
29         sort(words.begin(), words.end());
30         print("", 60, '-');
31         cout << endl;
32         for(int r = 0; r < rows; r++) {
33             
34             for (int c = 0; c < cols; c++) {
35                 
36                 int idx = c * rows + r;
37                 if (idx < n) print(words[idx],(c == cols - 1? max: max + 2), ' ');
38                 
39             }
40             
41             cout << endl;
42             
43         }
44         
45         
46     }
47     
48     return 0;
49     
50 }
51 
52 void print(const string &s, int len, char extra) {
53     
54     cout << s;
55     string::size_type str_size = s.size();
56     for (int i = 0; i < len - str_size; i++) {
57         cout << extra;
58     }
59 }


swp 2015-03-25 14:32 鍙戣〃璇勮
]]>
uva156 By sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/24/210152.htmlswpswpTue, 24 Mar 2015 09:13:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/24/210152.htmlhttp://www.shnenglu.com/sixleaves/comments/210152.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/24/210152.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210152.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210152.html 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 #include <map>
 5 #include <vector>
 6 using namespace std;
 7 
 8 map<stringint> cnt;
 9 vector<string> words;
10 
11 string formatWord(const string &s);
12 
13 int main() {
14     
15     string s;
16     while(cin >> s) {
17         
18         if (s[0] == '#') break;
19         words.push_back(s);
20         
21         string fw = formatWord(s);
22         if (!cnt.count(fw)) cnt[fw] = 0;
23         cnt[fw]++;
24     }
25     
26     vector<string> ans;
27     for (int i = 0; i < words.size(); i++) {
28         
29         if ( cnt[formatWord( words[i] ) ] == 1) ans.push_back(words[i]);
30     }
31     
32     sort(ans.begin(), ans.end());
33     for (int i = 0; i < ans.size(); i++) {
34         cout << ans[i] << endl;
35     }
36     return 0;
37 }
38 
39 string formatWord(const string &s) {
40     
41     string ans = s;
42     int str_size = ans.size();
43     for (int i = 0; i <str_size; i++) {
44         
45         ans[i] = tolower(ans[i]);
46         
47     }
48     sort(ans.begin(), ans.end());
49     return ans;
50 
51 }

swp 2015-03-24 17:13 鍙戣〃璇勮
]]>
uva540 Team Queue by sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/24/210144.htmlswpswpTue, 24 Mar 2015 00:31:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/24/210144.htmlhttp://www.shnenglu.com/sixleaves/comments/210144.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/24/210144.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210144.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210144.html棰樼洰鐨勫叿浣撹姹傛槸錛屾瘡嬈″叆闃熼噷鍓嶏紝鍏堜粠闃熷垪澶存壂鎻忓埌闃熷垪灝撅紝濡傛灉闃熷垪閲屾湁闃熷弸錛屽氨鎺掑湪闃熷弸浠殑鏈鍚庨潰(涓嶆槸璇ラ槦鍙嬬殑鍚庨潰錛屾槸鏁撮槦闃熷弸鐨勬渶鍚庨潰)銆傚鏋滄病鏈夐槦鍙嬪垯錛岀洿鎺ユ帓鍦ㄩ槦鍒楃殑鏈鍚庨潰銆傚嚭闃熷垪鐨勬病浠涔堢壒鍒殑浜嗐?br />
Keys:鍏跺疄鎴戜滑鍙互閫氳繃綆鍗曠殑妯℃嫙銆佸彂鐜般傜敱絎竴涓槦鍛樺埌鏈鍚庝竴涓槦鍛樺叆闃熷垪錛屾垨鑰呬腑闂存湁鍏朵粬鍑洪槦鍒椼傝闃熷垪濮嬬粓鍙互鐪嬫垚鏄袱涓槦鍒楃殑闃熷垪銆傚張鍥犱負棰樼洰瑕佹眰甯告暟鐨勬椂闂淬?br />鎵浠ユ垜浠笉鍙兘鎶婃椂闂存氮璐瑰湪鏌愪釜闃熷憳灞炰簬鍝竴涓槦閲岋紝鎵浠ュ彲浠ョ敤鏄犲皠銆佷篃灝辨槸map鏉ヨВ鍐寵繖涓棶棰樸俶ap<int, int>榪欎釜緇撴瀯鍒氬ソ鑳芥槧灝勮繖縐嶅叧緋匯傛帴涓嬪幓灝辨槸瑕佹湁涓涓猶2[maxn]鏉ヨ〃紺烘墍鏈夊垵濮嬪寲鐨勯槦鍒椼備竴涓猶鏉ヨ〃紺烘柊闃熷垪錛岃繖涓猶鍏跺疄灝辨槸闃熷垪鐨勯槦鍒椼?br />
 1 #include <queue>
 2 #include <string>
 3 #include <map>
 4 #include <iostream>
 5 using namespace std;
 6 
 7 const int maxn = 1024;
 8 
 9 
10 int main() {
11     
12     int t, n, k = 0;
13     while (cin >> t, t) {
14         // 鍒楅槦緙栧彿
15         cout << "Scenario #" << ++k << endl;
16         int qid = 1;
17         map<intint> team;
18         while (t--) {
19             cin >> n;
20             for (int i = 0; i < n; i++) {
21                 int uid;
22                 cin >> uid;
23                 team[uid] = qid;
24                 
25             }
26             qid++;
27         }
28         
29         // uid鏄槦鍛樼紪鍙楓?nbsp;tid鏄偅涓瀵歸槦鐨勭紪鍙?/span>
30         queue<int> q,q2[maxn];
31         string op;
32         int uid;
33         
34         while (cin >> op, op[0] != 'S') {
35             
36             // 鍏ラ槦鍒?/span>
37             if ('E' == op[0]) {
38                 cin >> uid;
39                 int tid = team[uid];
40                 if (q2[tid].empty()) q.push(tid);
41                 q2[tid].push(uid);
42 
43             }
44             // 鍑洪槦鍒?/span>
45             if ('D' == op[0]) {
46                 
47                 int tid = q.front();
48                 int x = q2[tid].front();
49                 q2[tid].pop();
50                 cout << x << endl;
51                 if (q2[tid].empty()) q.pop();
52                 
53             }
54             
55         }
56         
57         cout << endl;
58         
59     
60     }
61     
62 }


swp 2015-03-24 08:31 鍙戣〃璇勮
]]>
uva12096 The SetStack Computer By sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/23/210143.htmlswpswpMon, 23 Mar 2015 14:29:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/23/210143.htmlhttp://www.shnenglu.com/sixleaves/comments/210143.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/23/210143.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210143.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210143.html 1 #include <set>
 2 #include <string>
 3 #include <vector>
 4 #include <map>
 5 #include <stack>
 6 #include <iostream>
 7 #include <algorithm>
 8 #define ALL(x) x.begin(), x.end()
 9 #define INS(x) inserter(x, x.begin())
10 
11 using namespace std;
12 
13 typedef set<int> Set;
14 map<Set, int> IDCache;
15 vector<Set> Setcache;
16 // 涓昏鐨勬兂娉曟槸鑳芥兂鍒扮敤map<set<int>, int>榪欑鏁版嵁緇撴瀯鏉ユ妸闆嗗悎鏄犲皠鎴愭暣鏁?br />17 // 鍏抽敭瀹炵幇鍦↖D鍑芥暟錛屽浜庣粰瀹氱殑set<int>閮借兘榪斿洖涓涓敮涓緙栧彿銆乿ector铏界劧涓嶈兘淇濊瘉鍏冪礌鐨勫敮涓鎬с?br />18 // 浣嗘槸鎴戜滑鍙互鍏堝map榪涜媯鏌ユ潵淇濊瘉vector涓厓绱犵殑鍞竴鎬э紝榪欐牱姣忎釜鍏冪礌灝辮兘鍞竴緙栧彿錛屽垰濂藉彲浠ュ埄鐢ㄤ粬浠殑鏁存暟绱㈠紩銆?br />19 // 鍏朵腑set_union銆乻et_intersection涓緱瀹炵幇鍘熺悊涓嶆槸閲嶇偣錛屽厛瀛︿細鎬庝箞鐢ㄦ墠鏄噸鐐廣?br />20 // ID鍑芥暟瀹炵幇浜嗗鏂扮殑闆嗗悎瀛樺偍錛屽茍涓?/span>
21 int ID(Set x);
22 int main() {
23 
24     
25     stack<int> s;
26     int t, n;
27     string op;
28     cin >> t;
29     while (t--) {
30         cin >> n;
31         IDCache.clear();
32         Setcache.clear();
33         for (int i = 0; i < n; i++) {
34 
35             cin >> op;
36             if (op[0] == 'P') s.push(ID(Set())); // Set()灝辨槸絀洪泦
37             else if(op[0] == 'D') s.push(s.top());
38             else {
39                 
40                 Set x1 = Setcache[s.top()]; s.pop();
41                 Set x2 = Setcache[s.top()]; s.pop();
42                 Set x;
43                 if (op[0] == 'U') set_union (ALL(x1), ALL(x2), INS(x));
44                 if (op[0] == 'I') set_intersection (ALL(x1), ALL(x2), INS(x));
45                 if (op[0] == 'A') { x = x2; x.insert(ID(x1)); }
46                 s.push(ID(x));
47                 
48             }
49             
50             cout << Setcache[s.top()].size() << endl;
51         }
52         cout << "***" << endl;
53     
54     }
55     return 0;
56 }
57 
58 // 鐩稿綋浜庢暟鎹簱涓緱auto_increment, 榪斿洖涓涓敮涓鐨処D鍊?/span>
59 int ID(Set x) {
60     
61     if (IDCache.count(x)) return IDCache[x];
62     Setcache.push_back(x);
63     return IDCache[x] = Setcache.size() - 1;
64 
65 }

swp 2015-03-23 22:29 鍙戣〃璇勮
]]>
uva10815 by sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/16/210057.htmlswpswpMon, 16 Mar 2015 10:28:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/16/210057.htmlhttp://www.shnenglu.com/sixleaves/comments/210057.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/16/210057.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210057.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210057.html鍓嶈呯敤浜庢妸stringstream鐨勮繑鍥瀞tring緙撳瓨錛屽悗鑰呮槸鎶妔tring瀵硅薄鍖呰鎴恠tringstream瀵硅薄銆俿tringstream綾誨瓨鍦ㄤ簬sstream澶存枃浠朵腑銆傚叾鏄嫭绔嬩簬鏍囧噯I/O浣嗘湁綾諱技
鍔熻兘鐨勭被銆俢lear涓昏鏄負浜嗗嬈′嬌鐢╯tringstream錛屽洜涓簊tringstream姣忔鐨勬瀯閫犻兘鍗佸垎鑰楁椂錛屾墍浠ユ渶鍚庤兘澶氭錛屽弽澶嶄嬌鐢紝灝卞鍚岄潰鍚戝璞¢噷闈㈢殑鍗曚緥妯″紡銆?br />浠g爜濡備笅錛?br />
 1 #include <iostream>
 2 #include <string>
 3 #include <set>
 4 #include <sstream>
 5 
 6 
 7 using namespace std;
 8 
 9 set<string> dict;
10 stringstream ss;
11 
12 /*
13  涓昏瀛︿範涓や釜閲嶇偣stringstream鐨勭敤娉曚笌set瀹瑰櫒鐨刬nsert銆佽凱浠e櫒鐨勭敤娉曘?br />14  */
15 int main() {
16 
17     string s,buf;
18     
19     while (cin >> s) {
20         int len = s.size();
21         for (int i = 0; i < len; i++) {
22             if (isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' ';
23         }
24         ss.clear();
25         ss.str(s);
26         while (ss >> buf) dict.insert(buf);
27     }
28     
29     for (set<string>::iterator it = dict.begin(); it != dict.end(); ++it)
30         cout << *it << endl;
31     return 0;
32 }


swp 2015-03-16 18:28 鍙戣〃璇勮
]]>
uva 101 by sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/16/210052.htmlswpswpMon, 16 Mar 2015 07:03:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/16/210052.htmlhttp://www.shnenglu.com/sixleaves/comments/210052.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/16/210052.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210052.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210052.html鎺ヤ笅鏉ュ緱鎬濊礬鏄嚜欏跺悜涓嬬殑鏂瑰紡錛岄愭瀹屽杽紼嬪簭銆傞鍏堟牴鎹彁璁垪鍑轟笅琛ㄣ?br />1.move a onto b
clear_above(a) && clear_above(b);
insert a above b;

2.move a over b
clear(a)
insert a above bs

3.pile a onto b
clear(b)
insert as above b

4.pile a over b
insert as above bs

瑙傚療鍙互鎻愬彇鍑簃ove鐨勮瘽蹇呮湁clear_above(a)銆乷nto蹇呮湁clear_above(b).
鑰宨nsert 鍔ㄤ綔涓嶇b鏄湪p[b]鐨勯《閮ㄨ繕鏄閮ㄣ傞兘鏄痯[b].push_back(a鎴朼浠ヤ笂鐨勬湪鍧?
鎵浠ュ彲浠ユ娊鍙栨垚pile_into(pa, ha, pb);

鑰冭檻瀹岃繖浜涳紝寮濮嬪啓妗嗘灦銆傚涓?br />
 1 
 2 #include <cstdio>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 using namespace std;
 7 
 8 const int maxn = 64;
 9 int n;
10 vector<int> a[maxn];
11 int find_block(int a, int& h);
12 void clear_above(int p, int h);
13 void pile_into(int pa, int ha, int pb);
14 void print();
15 int main() {
16 
17     
18     
19     string s1, s2;
20     scanf("%d", &n);
21     for (int i = 0; i < n ; i++) {
22         a[i].push_back(i);
23     }
24     
25     while (cin >> s1, s1 != "quit") {
26         int ba,bb;
27         cin >> ba >> s2 >> bb;
28         int ha = 0,hb = 0;
29         int pa = find_block(ba, ha);
30         int pb = find_block(bb, hb);
31         if (pa == pb) continue;
32         
33         if (s1 == "move") clear_above(pa, ha);
34         if (s2 == "onto") clear_above(pb, hb);
35         pile_into(pa, ha, pb);
36     }
37     
38     print();
39     return 0;
40 }
 
鎺ヤ笅鏉ワ紝瀹屾垚紼嬪簭鍏跺畠閮ㄥ垎錛屾寜鐓ф鏋剁殑鎰忔濓紝閫愭瀹屽杽銆傚涓?br />
 1 void print() {
 2     
 3     for (int i = 0; i < n; i++) {
 4         printf("%d:",i);
 5         for (int h = 0; h < a[i].size(); h++) {
 6             printf(" %d", a[i][h]);
 7         }
 8         printf("\n");
 9     }
10 }
11 
12 int find_block(int ba, int& h) { 
13     
14     for (int i = 0; i < n; i++) {
15         
16         int vec_size = a[i].size();
17         for (h = 0; h < vec_size; h++) {
18             if (ba == a[i][h]) return i;
19         }
20         
21     }
22     return -1;
23 }
24 
25 void clear_above(int p, int h) {
26     int vec_size = a[p].size();
27     for (int i = h + 1; i < vec_size; i++) {
28         
29         int b = a[p][i];
30         a[b].push_back(b);
31         
32     }
33     a[p].resize(h + 1);
34 }
35 
36 void pile_into(int pa, int ha, int pb) {
37     
38     int vec_size = a[pa].size();
39     
40     for (int i = ha; i < vec_size; i++) {
41         a[pb].push_back(a[pa][i]);
42     }
43     a[pa].resize(ha);
44 }


swp 2015-03-16 15:03 鍙戣〃璇勮
]]>
uva 1589 by sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/15/210044.htmlswpswpSun, 15 Mar 2015 08:42:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/15/210044.htmlhttp://www.shnenglu.com/sixleaves/comments/210044.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/15/210044.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210044.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210044.html
  1 #include <stdio.h>
  2 #include <string.h>
  3 #define N 12
  4 
  5 char brd[N][N];
  6 int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};
  7 int hx[] = {-2,-1,-2,-1,1,2,1,2};
  8 int hy[] = {-1,-2,1,2,-2,-1,2,1};
  9 int tx[] = {-1,-1,-1,-1,1,1,1,1};
 10 int ty[] = {-1,-1,1,1,-1,-1,1,1};
 11 int cr[2], cc[2];
 12 
 13 
 14 int check(intint);
 15 
 16 int main() {
 17     
 18     int t, bX, bY;
 19     char s[5];
 20     while (scanf("%d%d%d",&t, &bX, &bY), t || bX || bY) {
 21         
 22         memset(brd, 0, sizeof(brd));
 23         cr[0] = cc[0] = cr[1] = cc[1] = 0;
 24         
 25         for (int i = 0; i < t; i++) {
 26             
 27             int rX, rY;
 28             scanf("%s%d%d", s, &rX, &rY);
 29             if ('C' == s[0]) {
 30                 
 31                 if (cr[0]) cr[1] = rX, cc[1] = rY;
 32                 else cr[0] = rX, cc[0] = rY;
 33             }
 34             brd[rX][rY] = s[0];
 35         }
 36         
 37         // 鍒ゆ柇鏄惁鍥涗釜鏂瑰悜閮戒細琚皢鍐?鎴栬呮棤璺彲璧扮殑鏂瑰悜涔熻涓烘槸琚皢鍐?/span>
 38         int cnt = 0;
 39         for (int i = 0; i < 4; i++)
 40             cnt += check(bX + dx[i], bY + dy[i]);
 41         
 42         if (cnt < 4) puts("NO");
 43         else puts("YES");
 44         
 45     }
 46     
 47 }
 48 
 49 int check(int r, int c) {
 50     
 51     // 瓚婄晫錛屾棤璺彲璧?/span>
 52     if (r < 1 || r > 3 || c < 4 || c > 6) return 1;
 53     
 54     
 55     // 鍥犱負鎴戜滑娌℃硶淇濊瘉杞︿腑闂存湁娌℃湁鍏朵粬媯嬪瓙錛屾墍浠ュ繀欏諱粠榪戝埌榪滀竴鏍兼牸媯鏌?br /> 56     // 杞﹀湪鍚岃涓斾腑闂存棤媯嬪瓙
 57     for (int j = c - 1; j > 0; j--) {
 58         if (brd[r][j])
 59             if ('R' == brd[r][j]) return 1;
 60             else break;
 61     }
 62     
 63     for (int j = c + 1; j <= 9; j++) {
 64         
 65         if (brd[r][j])
 66             if ('R' == brd[r][j]) return 1;
 67             else break;
 68     }
 69     
 70     
 71     // 杞﹀湪鍚屽垪涓斾腑闂寸墿媯嬪瓙
 72     for (int j = r - 1; j > 0; j--) {
 73         
 74         if (brd[j][c])
 75             if ('R' == brd[j][c]) return 1;
 76             else break;
 77         
 78     }
 79     
 80     for (int j = r + 1; j <=10; j++) {
 81         
 82         if (brd[j][c])
 83             if ('R' == brd[j][c] || 'G' == brd[j][c]) return 1;
 84             else break;
 85         
 86     }
 87     
 88     // 鐐皢鍐?/span>
 89     for (int k = 0; k < 2; k++) {
 90         
 91         // 琛屾湁鐐?/span>
 92         if (r == cr[k]) {
 93             int cnt = 0;
 94             for (int j = c - 1; j > cc[k]; j--) if (brd[r][j]) ++cnt;
 95             if (cnt == 1) return 1;
 96             cnt = 0;
 97             for (int j = c + 1; j < cc[k]; j++) if (brd[r][j]) ++cnt;
 98             if (cnt == 1) return 1;
 99             
100         }
101         
102         // 鍒楁湁璺?/span>
103         if (c == cc[k]) {
104             int cnt = 0;
105             for (int j = r - 1; j > cr[k]; j--) if (brd[j][c]) ++cnt;
106             if (cnt == 1) return 1;
107             cnt = 0;
108             for (int j = r + 1; j < cr[k]; j++) if (brd[j][c]) ++cnt;
109             if (cnt == 1) return 1;
110         }
111         
112         
113     }
114     
115     // 椹皢鍐?椹殑8涓柟浣?/span>
116     for(int k = 0; k < 8; ++k) {
117         
118         int tr = r + hx[k], tc = c + hy[k];
119         if (tr < 1 || tr > 10 || tc < 1 || tc > 9) continue;
120         if (brd[tr][tc] == 'H' && (!brd[r + tx[k]][c + ty[k]]))
121             return 1;
122         
123     }
124     return 0;
125 }


swp 2015-03-15 16:42 鍙戣〃璇勮
]]>
UVA 213 By sixleaveshttp://www.shnenglu.com/sixleaves/archive/2015/03/13/210027.htmlswpswpFri, 13 Mar 2015 12:06:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/03/13/210027.htmlhttp://www.shnenglu.com/sixleaves/comments/210027.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/03/13/210027.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/210027.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/210027.html 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 
 5 int readChar();
 6 int readInt(int c);
 7 int readCodes();
 8 
 9 /*
10  1.璇誨彇瀛楃鏃跺欏浣曡繃婊ゆ帀鎹㈣絎﹀彿錛屽吋瀹圭被unix鍜寃indows鎿嶄綔緋葷粺 readChar()
11  2.鐔熺粌鎺屾彙灝嗕簩榪涘埗瀛楃涓叉槧灝勫埌鏁扮粍鐨勬暟鎹粨鏋?榪欎釜鏁版嵁緇撴瀯鏄釜浜屽厓緇勶紝鎴戜滑鍙互鐢ㄨ浜屽厓緇勫敮涓紜畾涓涓暱搴︿負len鐨勪簩榪涘埗瀛楃涓?br />12  錛坙en, value錛?nbsp;---- > code[len][value]
13  
14  */
15 
16 int main() {
17 
18     
19     while ( readCodes() ) { // 璇葷紪鐮佸ご
20         
21         for (;;) {  // 璇諱俊鎭?/span>
22             
23             int len = readInt(3);
24             if (0 == len) break// 鍏?璇ヤ俊鎭粨鏉?/span>
25             
26             for (;;) {  // 璇諱俊鎭
27                 
28                 int v = readInt(len);
29                 
30                 if (v == (1 << len) - 1break// 鍏?涓涓俊鎭緇撴潫
31                 putchar(code[len][v]);
32                 
33             }
34             
35         }
36         
37         putchar('\n');
38     }
39 }
40 
41 
42 int readInt(int l) {
43     
44     int v = 0;
45     //宸茬粡璇誨彇浜? - l涓瓧絎?/span>
46     while (l--) {
47         
48         v = v * 2 + readChar() - '0';
49         
50     }
51     return v;
52     
53 }
54 
55 
56 char readChar() {
57     
58     char ch;
59     do {
60         
61         ch = getchar();
62         
63     }while ( '\n' != ch || '\r' != ch )
64     return ch;
65 }
66 
67 
68 int readCodes() {
69     
70     
71     memset(code, 0sizeof(code));
72     
73     // 鍥犱負鍙兘璇誨彇緙栫爜澶寸嫭鍗犱竴琛岋紝鎵浠ユ垜浠彲鑳借鍙栫紪鐮佸ご鏃跺欎細璇誨彇鍒頒笂涓嬈$殑鍥炶濺鎹㈣錛屾墍浠ヨ浣跨敤readChar鍑芥暟
74     code[1][0= readChar();
75     
76     for (int len = 2; len < 8; len++) {
77         
78         for (int v = 0; v < (1 << len) - 1; v++) {
79             
80             char ch = getchar();
81             if ( EOF == ch ) return 0;
82             if ( '\n' == ch || '\r' == ch) return 1;
83             code[len][v] = ch;
84             
85         }
86         
87     }
88     return 1;
89     
90     
91 }

swp 2015-03-13 20:06 鍙戣〃璇勮
]]>
UVA 10474http://www.shnenglu.com/sixleaves/archive/2015/02/12/209800.htmlswpswpThu, 12 Feb 2015 02:43:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/12/209800.htmlhttp://www.shnenglu.com/sixleaves/comments/209800.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/12/209800.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209800.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209800.html鍏蜂綋鐢ㄥ埌浜咰++ STL鐨勪袱涓嚱鏁版ā鏉夸竴涓槸sort銆佷竴涓槸lower_bound,lower_bound(begin, end, v);
lower_bound涓巗trchr綾諱技錛屼絾瀹冧嬌鐢ㄧ殑鏄凱浠e櫒begin涓巈nd榪斿洖鐨勬槸澶т簬絳変簬v鐨勬渶灝忔暟鎵鍦ㄧ殑榪唬鍣紝
浣跨敤璇ユā鏉垮嚱鏁伴渶瑕佹敞鎰忕殑闂鏄紝蹇呴』鏄拡瀵瑰凡緇忔帓搴忓ソ寰楁暟瀛楋紝鍏蜂綋浠g爜濡備笅銆?/div>
 1 #include <cstdio>
 2 #include <algorithm>
 3 
 4 using namespace std;
 5 const int maxn = 10000;
 6 
 7 
 8 int main() {
 9     
10     int n, q, x, a[maxn], kase = 0;
11     while (scanf("%d%d", &n, &q) == 2 && n) {
12         
13         for (int i = 0; i < n; i++) scanf("%d", &a[i]);
14         sort(a, a+n);
15         printf("CASE# %d:\n", ++kase);
16         while (q--) {
17             
18             scanf("%d", &x);
19             int p = lower_bound(a, a+n, x) - a;
20             if (a[p] == x) printf("%d found at %d\n", x, p + 1);
21             else printf("%d not found\n",x);
22             
23         }
24     }
25     return 0;
26 }


swp 2015-02-12 10:43 鍙戣〃璇勮
]]>UVA 253http://www.shnenglu.com/sixleaves/archive/2015/02/08/209765.htmlswpswpSat, 07 Feb 2015 17:42:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/08/209765.htmlhttp://www.shnenglu.com/sixleaves/comments/209765.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/08/209765.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209765.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209765.html/Files/sixleaves/253.pdf 
棰樼洰鍦ㄤ笂闈紝鍙互鑷繁涓嬭澆錛岃繖閬撲竴寮濮嬫病浠涔堟濊礬錛屽悗鏉ヤ粩緇嗘兂鎯籌紝紿佺劧鏈変簡鐐圭伒鎰燂紝浣嗘槸榪樻槸鎵句笉鍒版瘮杈冪畝鍗曠殑鍔炴硶
紼嬪簭榪樻湁浼樺寲鐨勫湴姝ワ紝鐢ㄥ埌鐨勫叏灞鍙橀噺鏈夌偣澶氥?/div>
鎴戠殑鎬濊礬鏄細姣忎釜鏁板瓧閮芥湁涓涓綅浜嶵op涔熷氨鏄渶欏跺緱鏃跺欙紝鍙鍦ㄨ繖鏃跺欙紝绔栫洿鏃嬭漿4嬈★紝鍒嗗埆鍒ゆ柇灝卞彲浠ョ煡閬撴槸鍚﹀瓨鍦ㄧ浉鍚岀殑cube浜嗐?/div>
紼嬪簭涓諱綋妗嗘灦鎸烘竻鏅扮殑錛屼絾鏄湁涓鐐瑰氨鏄笅鏍囨病澶勭悊濂斤紝鏈夊叴瓚g殑錛屽彲浠ヨ嚜宸辯粺涓涓涓嬨?/div>
by sixleaves
 1 #include <stdio.h>
 2 
 3 //  鏋氫婦鍚勪釜鏁板瓧浣嶄簬"涓?鐨勪竴縐嶅彲鑳芥儏鍐?br />  4 //  璇ユ儏鍐典笅錛屽悇涓暟瀛楁墍澶勭殑浣嶇疆
 5 int cubeTop[7][7] = {
 6     {0,0,0,0,0,0,0},
 7     {0,1,2,3,4,5,6},
 8     {0,2,6,3,4,1,5},
 9     {0,3,2,6,1,5,4},
10     {0,4,2,1,6,5,3},
11     {0,5,1,3,4,6,2},
12     {0,6,5,3,4,2,1}
13 };
14 
15 
16 int lastCube[7] = {0};
17 int curCube[7] = {0};
18 
19 int isFind;
20 
21 // [0,6)  [6,12)--涓哄彟澶栦竴涓猚ube
22 char s[15] = {0};
23 void turn();
24 void update();
25 int isSameCube();
26 int main() {
27     
28     while (scanf("%s",s) != EOF) {
29     
30         // 鏋氫婦top闈㈡暟瀛?/span>
31         isFind = 0;
32         for (int i = 1; i <=6; i++) {
33             
34             //  鍒濆鍖栧綋鍓嶇瓫瀛?/span>
35             for (int k = 1; k <= 6; k++) {
36                 lastCube[k] = curCube[k] = cubeTop[i][k];
37             }
38             
39             // 绔栫洿杞姩4嬈$瓫瀛?/span>
40             for (int j = 0; j < 4; j++) {
41                 
42                 turn();
43                 
44                 if (isSameCube()) {
45                     isFind = 1;
46                     break;
47                 }
48                 
49             }
50             
51             if (isFind) {
52                 break;
53             }
54         }
55         
56         printf( isFind == 1? "TRUE\n" : "FALSE\n");
57         
58     }
59     return 0;
60 }
61 
62 int isSameCube() {
63     
64     //鍒嗗埆姣旇緝瀵瑰簲6涓潰
65     for (int i = 0; i < 6; i++) {
66         if (s[curCube[i + 1] - 1] != s[i + 6])
67             return 0;
68     }
69     return 1;
70 }
71 
72 void turn() {
73     
74     curCube[2] = lastCube[3];
75     curCube[4] = lastCube[2];
76     curCube[5] = lastCube[4];
77     curCube[3] = lastCube[5];
78     //  鏇存柊lastCube
79     update();
80 }
81 
82 void update() {
83     
84     lastCube[2] = curCube[2];
85     lastCube[4] = curCube[4];
86     lastCube[5] = curCube[5];
87     lastCube[3] = curCube[3];
88     
89 }


swp 2015-02-08 01:42 鍙戣〃璇勮
]]>UVA 489 http://www.shnenglu.com/sixleaves/archive/2015/02/07/209763.htmlswpswpSat, 07 Feb 2015 05:29:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/07/209763.htmlhttp://www.shnenglu.com/sixleaves/comments/209763.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/07/209763.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209763.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209763.html

 1 #include <stdio.h>
 2 #include <string.h>
 3 #define MAXN 1024
 4 
 5 int left, chance;
 6 int win, lose;
 7 void guess(char ch);
 8 
 9 char p[MAXN] = {0}, g[MAXN] = {0};
10 int main() {
11     
12     int r = 0;
13     
14     while (scanf("%d%s%s",&r, p, g) == 3 && r != -1) {
15         
16         printf("Round %d\n", r);
17         win = lose = 0;
18         left = strlen(p);
19         chance = 7;
20         for (int i = 0; g[i]; i++) {
21             
22             guess(g[i]);
23             
24             if (win || lose) break;
25             
26         }
27         
28         if (win) printf("You win.\n");
29         else if(lose) printf("You lose.\n");
30         else printf("You chickened out.\n");
31         
32     }
33     return 0;
34 }
35 
36 
37 void guess(char ch) {
38     
39     int finded = 0;
40     for (int i = 0; p[i]; i++) {
41         
42         if (ch == p[i]) {
43             p[i] = ' ';
44             left--;
45             finded = 1;
46             
47         }
48         
49     }
50     
51     if (!finded) --chance;
52     if (!chance) lose = 1;
53     if (!left) win = 1;
54     
55 }

by sixleaves


swp 2015-02-07 13:29 鍙戣〃璇勮
]]>
UVA 227http://www.shnenglu.com/sixleaves/archive/2015/02/06/209753.htmlswpswpFri, 06 Feb 2015 02:24:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/06/209753.htmlhttp://www.shnenglu.com/sixleaves/comments/209753.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/06/209753.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209753.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209753.html鍐欏緱姣旇緝闀匡紝娌℃湁榪涜閲嶆瀯錛屽氨榪欐牱鍚с俫etchar()絳塈/O铏界劧浼氳鍙栧洖杞︼紝浣嗘槸瑕佹寜涓嬪洖杞︼紝浜х敓涓柇錛屽湪浼氱粨鏉熻緭
鍛婅瘔榪欎簺I/O鍑芥暟鏉ヨ鍙?=銆傛諱箣榪欓鐩紝娌′粈涔堢壒鍒殑鎬濇兂錛屽畬鍏ㄦ槸妯℃嫙棰橈紝鑳藉啓:?鐨勮鍙ワ紝灝介噺鍐欙紝綆鍖栦唬鐮?/div>
榪樻湁浠g爜瀹佹効涓ュ瘑鍟板棪錛屼篃涓嶈鏈塀ug

#include <stdio.h>

#include <string.h>

typedef struct {

    int r;

    int c;

} Point;


int main() {

    

    const int maxn = 5;

    char puzzle[maxn][maxn] = {0};

    int kase = 0;

    int first = 1;

    for (;;) {

        

        //  1.鍏堣鍙栦竴涓瓧絎?span style="font-family: Menlo;">,鐪嬫槸涓嶆槸Z,涓嶆槸Z寰楃湅鐪嬫槸涓嶆槸絀哄瓧絎?/p>

        char ch;

        ch = getchar();

        if (ch == 'Z') break;

        else {

            puzzle[0][0] = ch;

            first == 1? first = 0: printf("\n");

        }

        

        Point empty;

        if (ch == ' ') { empty.r = 0, empty.c = 0; }

        

        //  2.璇誨彇Puzzle鍒濆鍖栧竷灞

        for (int i = 1; i < 25; ) {

            ch = getchar();

            if (ch == ' ') {

                puzzle[ empty.r = i / 5 ][ empty.c = i % 5 ] = ch;

                i++;

            }

            if (ch != ' ' && ch != '\n' && ch != '\t' && ch != '\r') {

                puzzle[ i/5 ][ i%5 ] = ch;

                i++;

            }

        }

        

        //  3.鎵ц鎸囦護

        int configuration = 1;

        while ((ch = getchar()) != '0') {

            

            if (ch == '\n' || ch == ' ' || !configuration) continue;

            int row = empty.r, col = empty.c;

            if (configuration) {

                switch (ch) {

                        

                    case 'A':

                        if (row - 1 >= 0) {

                            puzzle[row][col] = puzzle[row - 1][col];

                            puzzle[row - 1][col] = ' ';

                            empty.r = row - 1;

                            empty.c = col;

                        }else {

                            configuration = 0;

                        }

                        break;

                    case 'B':

                        if (row + 1 < maxn) {

                            puzzle[row][col] = puzzle[row + 1][col];

                            puzzle[row + 1][col] = ' ';

                            empty.r = row + 1;

                            empty.c = col;

                        }else {

                            configuration = 0;

                        }

                        break;

                    case 'R':

                        if (col + 1 < maxn) {

                            puzzle[row][col] = puzzle[row][col + 1];

                            puzzle[row][col + 1] = ' ';

                            empty.r = row;

                            empty.c = col + 1;

                        }else {

                            configuration = 0;

                        }

                        break;

                    case 'L':

                        if (col - 1 >= 0) {

                            puzzle[row][col] = puzzle[row][col - 1];

                            puzzle[row][col - 1] = ' ';

                            empty.r = row;

                            empty.c = col - 1;

                        }else {

                            configuration = 0;

                        }

                        break;

                    default:

                        configuration = 0;

                        break;

                        

                }

            }

            

        }

        //  4.鍚冩帀鍥炶濺

        ch = getchar();

        

        //  5.杈撳嚭

        if (!configuration) {

            printf("Puzzle #%d:\nThis puzzle has no final configuration.\n", ++kase);

        }else {

            printf("Puzzle #%d:\n", ++kase);

            for (int row = 0; row < maxn; row++) {

                

                for (int col = 0; col < maxn; col++) {

                    

                    printf(col == maxn - 1 ? "%c" : "%c ", puzzle[row][col]);

                    

                }

                printf("\n");

            }

        }

        

    }

    

    return 0;

}



swp 2015-02-06 10:24 鍙戣〃璇勮
]]>UVA 445http://www.shnenglu.com/sixleaves/archive/2015/02/05/209748.htmlswpswpThu, 05 Feb 2015 12:01:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209748.htmlhttp://www.shnenglu.com/sixleaves/comments/209748.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209748.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209748.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209748.html
榪樻湁鍙﹀涓涓紝len % t == 0鏄繀欏誨緱錛屽洜涓哄彧鏈夋槸鍛ㄦ湡鍊嶆暟鐨勬墠鑳芥眰鍑哄懆鏈熴備笉鐒跺錛歛bcdabc姹傚嚭鐨勫懆鏈熷氨鍙樻垚浜?.

 1 #include <stdio.h>
 2 #include <string.h>
 3 const int maxn = 1024;
 4 char buf[maxn] = {0};
 5 int isT(char * buf, int len,int t);
 6 int main() {
 7     
 8     int n;
 9     while (~scanf("%d",&n))
10         while ( n > 0 ) {
11             
12             //  杈撳叆
13             scanf("%s",buf);
14             int len = strlen(buf);
15             
16             //  璁$畻鏈灝忓懆鏈?浠庡皬鍒板ぇ鏋氫婦
17             for (int t = 1; t <= len; t++) {
18                 if (len % t == 0)
19                     if (isT(buf, len, t)) {
20                         printf("%d\n", t);
21                         break;
22                     }
23             }
24             
25             if (--n) printf("\n");
26         }
27     
28     return 0;
29 }
30 
31 int isT(char * buf, int len,int t) {
32     
33     for (int i = t; i < len; i++) {
34         
35         if (buf[i % t] != buf[i]) {
36             
37             return 0;
38         }
39     }
40     
41     return 1;
42 }

by sixleaves


swp 2015-02-05 20:01 鍙戣〃璇勮
]]>
UVA 1225http://www.shnenglu.com/sixleaves/archive/2015/02/05/209747.htmlswpswpThu, 05 Feb 2015 11:53:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209747.htmlhttp://www.shnenglu.com/sixleaves/comments/209747.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209747.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209747.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209747.html
 1 #include <stdio.h>
 2 const int maxn= 10008;
 3 int count[maxn][10] = {0};
 4 int main() {
 5     
 6     
 7     int n;
 8     char buf[maxn] = {0};
 9     
10     //璁$畻姣忎竴浣?/span>
11     for (int i = 1; i<= maxn; i++) {
12         
13         sprintf(buf,"%d", i);
14         for (int j = 0; buf[j]; j++) {
15             count[i][buf[j]-'0']++;
16         }
17         
18     }
19     
20     //寤虹珛鏁版嵁,闃叉閲嶅璁$畻
21     for (int i = 2; i <= maxn; i++) {
22         
23         for (int j = 0; j < 10; j++) {
24             
25             count[i][j] += count[i - 1][j];
26             
27         }
28     }
29     
30     scanf("%d", &n);
31     while (n > 0) {
32         int e;
33         scanf("%d", &e);
34         
35         for (int i = 0; i < 10; i++) {
36             printf( i == 9? "%d\n" : "%d ", count[e][i]);
37         }
38         
39         n--;
40     }
41 }
by sixleaves

swp 2015-02-05 19:53 鍙戣〃璇勮
]]>UVA 1586http://www.shnenglu.com/sixleaves/archive/2015/02/05/209746.htmlswpswpThu, 05 Feb 2015 11:37:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209746.htmlhttp://www.shnenglu.com/sixleaves/comments/209746.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209746.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209746.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209746.html
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <ctype.h>
 4 #define MAXN 100
 5 
 6 char buf[MAXN] = {0};
 7 double t[26] = {0};
 8 int readInt(char * buf, int i, int *num);
 9 int main() {
10     
11     int n;
12     int ch, num;
13     t['C'-'A'] = 12.01, t['H'-'A'] = 1.008;
14     t['O' - 'A'] = 16.00, t['N' - 'A'] = 14.01;
15     scanf("%d", &n);
16     
17     while (n > 0) {
18         
19         //  1.杈撳叆鏁版嵁
20         scanf("%s", buf);
21         int len = strlen(buf);
22         double sum = 0.0;
23         int i = 0;
24         
25         //  2.璁$畻
26         for (;;) {
27             
28             for (; buf[i]&&isalpha(buf[i]); i++) {
29                 sum += t[buf[i] - 'A'];
30             }
31             if (i >= len) break;
32             
33             //  2.1[i, e)涓烘暣鏁拌寖鍥?num涓烘暣鏁板?/span>
34             int e,num;
35             e = readInt(buf, i, &num);
36             sum += t[buf[i - 1] - 'A'] * (num - 1);
37             i = e;
38         }
39         
40         //  3.杈撳嚭緇撴灉
41         printf("%.3f\n", sum);
42         n--;
43     }
44     
45     return 0;
46 }
47 
48 //  濡傛灉娌℃湁鎵懼埌鍒欒繑鍥瀒
49 int readInt(char * buf, int i, int *num) {
50     int sum = 0;
51     int j;
52     for (j = i; buf[j] && isdigit(buf[j]); j++) {
53         sum *= 10;
54         sum += buf[j] - '0';
55     }
56     *num = sum;
57     return j;
58     
59 }
by sixleaves

swp 2015-02-05 19:37 鍙戣〃璇勮
]]>UVA 1585http://www.shnenglu.com/sixleaves/archive/2015/02/05/209735.htmlswpswpThu, 05 Feb 2015 01:09:00 GMThttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209735.htmlhttp://www.shnenglu.com/sixleaves/comments/209735.htmlhttp://www.shnenglu.com/sixleaves/archive/2015/02/05/209735.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/209735.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/209735.html
 1 #include <stdio.h>
 2 #include <string.h>
 3 #define MAXN 86
 4 int main() {
 5     
 6     int n;
 7     char buf[MAXN] = {0};
 8     scanf("%d", &n);
 9     typedef enum {
10         WordIn,
11         WordOut,
12     } Word;
13     while ( n--> 0) {
14         
15         scanf("%s", buf);
16         int sum = 0, b = 0, e = 0, len = strlen(buf);
17         buf[len++] = 'X', buf[len] = '\0';
18         Word word = WordOut;
19         
20         //  閬嶅巻瀛楃涓?/span>
21         for (int i = 0; buf[i]; i++) {
22             
23             //  璁板綍鍗曡瘝寮澶?/span>
24             if (buf[i] == 'O') {
25                 
26                 b = word == WordOut? ( word = WordIn, i) : b;
27                 
28             }else {
29                 
30                 //  璁板綍鍗曡瘝緇撳熬,騫朵綔緇熻
31                 if (word == WordIn) {
32                     word = WordOut;
33                     e = i;
34                     int max = e - b;
35                     sum += max*(max + 1) / 2;
36                 }
37                 
38             }
39         }
40         printf("%d\n", sum);
41     }
42     return 0;
43 }
by sixleaves

swp 2015-02-05 09:09 鍙戣〃璇勮
]]>
鍏充簬鎬庝箞鍒ゆ柇寰幆鐨勬鏁?/title><link>http://www.shnenglu.com/sixleaves/archive/2014/09/23/208389.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Tue, 23 Sep 2014 13:02:00 GMT</pubDate><guid>http://www.shnenglu.com/sixleaves/archive/2014/09/23/208389.html</guid><wfw:comment>http://www.shnenglu.com/sixleaves/comments/208389.html</wfw:comment><comments>http://www.shnenglu.com/sixleaves/archive/2014/09/23/208389.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/sixleaves/comments/commentRss/208389.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/sixleaves/services/trackbacks/208389.html</trackback:ping><description><![CDATA[<strong>鍦ㄥ啓紼嬪簭涓紝鎴戜滑緇忓父瑕佸垽鏂紝鎴栬呭啓涓驚鐜紝鍏蜂綋璁╁叾寰幆鍑犳錛岃繖涓庝箞璁$畻銆?br />鎴戝垎鍒婦鍑犱釜渚嬪瓙銆?br />eg1錛歠or (i = 0; i < n; i++);<br />榪欎釜鏄ぇ瀹跺啀鐔熸倝涓嶈繃鐨勪簡錛屼負浠涔堝畠鏄痭嬈″驚鐜紝濡傛灉鎴戣兘鐢ㄦ暟瀛︾殑瑙掑害鐪嬫槸榪欐牱鐨勶紝棣栧厛i鐨勫彇鍊艱寖鍥翠腑錛屾瘡涓暣鏁板搴斾竴涓?br />寰幆錛屾墍浠ユ墍璋撶殑寰幆嬈℃暟錛屼篃灝辨槸榪欎釜鑼冨洿鍐呯殑鏁存暟鐨勪釜鏁般傝屼笂榪扮殑寰幆鑼冨洿鏄痆0, n).瀹冪殑鏁存暟涓暟灝辨槸n - 0 = n錛屽彧鏈?br />瀵逛簬鍗婇棴鍚堝崐寮鏀劇殑鍖洪棿鑳借繖鏍瘋綆楋紝榪欎篃鏄負浠涔堜粠0寮濮嬭鏁扮殑濂藉涔嬩竴銆備竴鐩簡鐒躲?br />eg2錛?br />while(L--) {<br />}<br />榪欎釜寰幆寰幆鍑犳鍛紝棣栧厛鎴戜滑紜畾L鐨勬湁鏁堣寖鍥達紝鐢變簬鏄悗緗噺鍑忥紝鎵浠ユ湁鏁堣寖鍥存槸[L, 0).鎵浠ュ驚鐜篃鏄疞嬈?br />濡傛灉鏄?br />while(--L){},閭h寖鍥村氨鏄痆L-1, 0),鎵浠ュ叾寰幆嬈℃暟鏄疞 - 1</strong><img src ="http://www.shnenglu.com/sixleaves/aggbug/208389.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/sixleaves/" target="_blank">swp</a> 2014-09-23 21:02 <a href="http://www.shnenglu.com/sixleaves/archive/2014/09/23/208389.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>UVA133http://www.shnenglu.com/sixleaves/archive/2014/09/23/208388.htmlswpswpTue, 23 Sep 2014 12:46:00 GMThttp://www.shnenglu.com/sixleaves/archive/2014/09/23/208388.htmlhttp://www.shnenglu.com/sixleaves/comments/208388.htmlhttp://www.shnenglu.com/sixleaves/archive/2014/09/23/208388.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/208388.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/208388.html棰樼洰鎻忚堪

涓轟簡緙╃煭棰嗘晳嫻庡搧鐨勯槦浼嶏紝NNGLRP鍐沖畾浜嗕互涓嬬瓥鐣ワ細姣忓ぉ鎵鏈夋潵鐢寵鏁戞祹鍝佺殑浜轟細琚斁鍦ㄤ竴涓ぇ鍦嗗湀錛岄潰鏈濋噷闈€傞夊畾涓涓漢涓虹紪鍙?1 鍙鳳紝鍏朵粬鐨勫氨浠庨偅涓漢寮濮嬮嗘椂閽堝紑濮嬬紪鍙風洿鍒?N銆備竴涓畼鍛樹竴寮濮嬮嗘椂閽堟暟錛屾暟 k 涓敵璇瘋咃紝鐒跺悗鍙︿竴涓畼鍛樼 N 涓欏烘椂閽堟柟鍚戞暟 m 涓敵璇瘋咃紝榪欎袱涓漢灝辮閫佸幓鍐嶆暀鑲層傚鏋滀袱涓畼鍛樻暟鐨勬槸鍚屼竴涓漢錛岄偅涓漢鍒欒閫佸幓浠庢斂錛岀劧鍚?涓畼鍛樺啀鍦ㄥ墿涓嬬殑浜洪噷闈㈢戶緇夌洿鍒版病浜哄墿涓嬫潵錛屾敞鎰忎袱涓閫?涓殑浜烘槸鍚屾椂璧版帀鐨勶紝鎵浠ュ氨鏈夊彲鑳戒袱涓畼鍛橀変腑涓涓漢銆?/p>

[緙栬緫]Input

杈撳叆鍚湁澶氱粍嫻嬭瘯璧勬枡錛屾瘡緇勬祴璇曡祫鏂欎竴鍒楀惈鏈変笁涓暟 N錛宬 鍜?m錛坘, m > 0錛?<N<20錛夈?褰撹緭鍏ヤ負 0 0 0 浠h〃杈撳叆緇撴潫銆?/p>

[緙栬緫]Output

瀵規瘡緇勬祴璇曡祫鏂欒緭鍑轟竴鍒椼傝緭鍑鴻閫変腑鐨勭敵璇瘋呯殑緙栧彿欏哄簭錛堜竴瀵逛竴瀵圭殑錛夈傛瘡涓暟鐨勫搴︿負 3 銆傛瘡涓瀵瑰墠闈㈢殑閭d釜緙栧彿涓洪嗘椂閽堟暟鐨勫畼鍛橀夊嚭鐨勶紝鍚庨潰鐨勯偅涓紪鍙蜂負欏烘椂閽堟暟鐨勫畼鍛橀夊嚭鐨勶紙浣嗘槸濡傛灉榪?涓畼鍛橀夊嚭鍚屼竴涓漢錛岄偅灝卞彧浼氭湁涓涓紪鍙鳳級銆傛瘡涓瀵?涔嬮棿浠ラ楀彿鍒嗗紑銆傛牸寮忚鍙傝僑ample Output銆?/p>

[緙栬緫]Sample Input

10 4 3 
13 17 42
7 8 47
0 0 0

[緙栬緫]Sample Output

 4 8, 9 5, 3 1, 2 6, 10, 7 
4 11, 10 1, 8 6, 13 7, 3, 5 12, 9 2
1 3, 5 7, 2 4, 6
榪欓亾棰樼洰鏈夌偣緇曪紝涔熻寰椾笉涓ュ瘑銆傝繖閲屼富瑕佽涓嬪嚑涓鏄撻敊鐨勫湴鏂廣?br />棣栧厛鏄綘姣忔鍦ㄥ啓紼嬪簭涔嬪墠錛岄兘瑕佸崄鍒嗘竻闄よ鍒欙紝棰樼洰涓殑浜烘槸鍥寸潃涓鍦堬紝鑰屼笖絎竴涓殑宸﹁竟鏄N涓漢錛屼篃灝辨槸瀹冩槸閫嗘椂閽堟爣鍙風殑銆傝繖涓崄鍒嗗叧閿?br />鍏舵鏄痝o鍑芥暟鐨勫疄鐜幫紝go鍑芥暟鏄暟榪嘗涓漢錛岃繑鍥炴渶鍚庝竴涓殑浣嶇疆銆傛垜騫朵笉璧炲悓錛屾煇浜涚増鏈暟緇勬槸浠?寮濮嬭鏁幫紝鍥犱負榪欐牱瀵逛簬琛ㄨ揪寮忕殑琛ㄨ揪鍗佸垎涓嶆柟渚褲備綘鍙互
鑷繁灝濊瘯鐢?鏉ュ仛錛屼細寰堜笉鏂逛究銆傚氨鏄洜涓篻o鍑芥暟鏄繖鏍蜂竴涓嚱鏁幫紝鎵浠ュ綋鎴戜滑鍦ㄤ笅涓嬈¤凱浠g殑鏃跺欑殑寮濮嬩綅緗紝涓瀹氭槸涓洪偅涓漢鍑哄幓鐨勪綅緗紝涔熷氨鏄痑[i]=0鐨勪綅緗?br />鎵浠ユ垜浠涓嬈¤凱浠g殑浣嶇疆錛屽師鏈珹鏄簲璇ュ湪浣嶇疆0錛孊鍦ㄤ綅緗畁-1銆傝繖鏃跺欏彧鑳芥槸A鍦╪-1鍜孊鍦?.錛堜綘鍙互鐢ㄦ暟瀛﹀綊綰蟲硶鐞嗚В錛夈?br />
 1 #include <stdio.h>
 2 
 3 #define MAXN 25
 4 int n,k,m;
 5 int a[MAXN];
 6 int go(int p, int d, int k);//鏁拌繃k涓漢錛屽紑濮嬩綅緗畃蹇呴』鏄暟1鏃跺欑殑鍓嶄竴涓綅緗?nbsp;
 7 int main() {
 8     while (scanf("%d%d%d", &n, &k, &m) == 3 && n) {
 9         for (int i = 0; i < n; i++) {
10             a[i] = i + 1;
11         }
12         int left = n;
13         int pA = n-1, pB = 0;
14         int pANext,pBNext;
15         while (left) {
16             pA = go(pA, 1, k);//1琛ㄧず閫嗘椂閽堬紝鍥犱負瀹冩槸閫嗘椂閽堟爣鍙?br />17             pB = go(pB, -1, m);//-1琛ㄧず欏烘椂閽?br />18             printf("%3d", pA + 1); left--;
19             if (pA != pB) { printf("%3d", pB + 1); left--;}
20             a[pA] = a[pB] = 0;
21             if (left) printf(",");
22         }
23         printf("\n");
24     }    
25     return 0;
26 }
27 int go(int p, int d, int L) {
28     while (L--) {
29         do { p = (p+n+d)%n;} while(a[p] == 0);
30     }
31     return p;
32 }
瑙f瀽:鑷充簬涓嬩竴涓綅緗負浠涔堟槸p = (p+n+d)%n.鍏跺疄寰堢畝鍗曘傚洜涓烘垜浠槸涓姝ユ璧扮殑錛屾墍浠ュ彧鏈変袱縐嶈竟鐣屾儏鍐點傚亣璁懼綋鍓嶄綅緗槸p(0=<p<n),
絎竴縐嶈竟鐣岋細p + 1 > n - 1錛屽嵆 p + 1姝ゆ椂搴旇鏄埌杈?浣嶇疆錛屼絾姝ゆ椂p + 1 = n錛屽鏋滄垜浠彇浣欐暟錛屽垯 錛坧+1)%T = 0,T = n(T琛ㄧず榪欎釜鍦嗗湀鐨勫懆鏈熷ぇ灝?銆?br />鍒氬ソ鑳界鍚堬紝鍙堝洜涓篢 = n錛屾墍浠?P+T+1)%T榪樻槸涓嶅彉鐨勩?br />絎簩縐嶈竟鐣? p - 1 < 0, 鍗?p - 1姝ゆ椂鐨勫兼槸-1錛屽浜庤繖縐嶆儏鍐靛彲浠ュ弽榪囨潵鐪嬶紝瀹冩槸鍚戝悗閫鍚?涓崟浣嶏紝鍙互鐪嬫垚鍚戝墠璧癟 - 1涓崟浣嶅嵆p -1 絳夋晥浜?p + T - 1
錛屾垜浠絳夊埌姝ゆ椂鐨勪綅緗紝鍐嶅幓浣欙紝(P+T-1)%T銆?br />瀵逛簬鎯呭喌涓銆佷簩銆傚彲浠ュ綊綰充負(P+T+d)%T,褰撲負欏烘椂閽堟槸d鍙?錛屽惁鍒?1.

swp 2014-09-23 20:46 鍙戣〃璇勮
]]>
A + B Problem II(hdu)http://www.shnenglu.com/sixleaves/archive/2014/09/04/208228.htmlswpswpThu, 04 Sep 2014 06:56:00 GMThttp://www.shnenglu.com/sixleaves/archive/2014/09/04/208228.htmlhttp://www.shnenglu.com/sixleaves/comments/208228.htmlhttp://www.shnenglu.com/sixleaves/archive/2014/09/04/208228.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/208228.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/208228.html榪欓亾棰樼洰鏄ぇ鏁板姞娉曘傛葷粨涓浜涗竴鐐圭粡楠屻?/strong>

錛?錛夋暣鍊煎嚱鏁扮殑搴旂敤銆傦紙榪欎釜涓嶆噦鐨勮瘽錛屽幓鐪嬫垜Math鏍忕洰涓嬫湁榪欎釜鍒嗘瀽錛?/strong>

錛?錛塻scanf銆乻printf鐨勫簲鐢?/strong>

錛?錛夊垎鍧楄綆楃殑鏍煎紡闂銆?/strong>

鍏堢洿鎺ョ湅浠g爜錛?br />      1 #include <iostream>

 2 #include <cstdio>
 3 #include <vector>
 4 #include <cstring>
 5 using namespace std;
 6 struct BigInteger {
 7     static const int BASE = 100000000;
 8     static const int WIDTH = 8;
 9     vector<int> s;
10     
11     BigInteger(long long num = 0) {
12         *this = num;
13     }
14     
15     BigInteger operator=(long long num) {
16         s.clear();
17         do {
18             s.push_back(num % BASE);
19             num /= BASE;
20         }while (num > 0);
21         return *this;
22     }
23     
24 
25     BigInteger operator=(const string& str) {
26         s.clear();
27         int x;
28         int len = (str.size() - 1) / WIDTH + 1;//榪欓噷鏈変漢鐪嬩笉鎳傦紝璇風湅鎴戝啓鐨勬暣鍊煎嚱鏁?nbsp;
29         for (int i = 0; i < len; i++) {
30             int end = str.size() - i * WIDTH;
31             int start = max(0, end - WIDTH);//紜畾鍒嗗壊鐨勫尯闂翠負[start, end)鏄乏闂彸寮錛岄暱搴﹀氨鏄痚nd - start 
32             sscanf(str.substr(start, end - start).c_str(), "%d", &x);
33             s.push_back(x);
34         }
35         return *this;
36     }
37     
38     BigInteger operator+(const BigInteger& bi) const{
39         BigInteger temp;
40         temp.s.clear();
41         for (int i = 0,g = 0;;i++) {
42             
43             if (g == 0 && i >= s.size() && i >= bi.s.size()) break;
44             int x = g;
45             if (i < s.size()) x += s[i];
46             if (i < bi.s.size()) x += bi.s[i];
47             temp.s.push_back(x % BASE);
48             g = x / BASE;
49         }
50         return temp;    
51     }    
52     
53     BigInteger operator +=(const BigInteger& b) {
54         *this = *this + b;return *this;
55     }
56 };
57 
58 istream& operator >>(istream &in, BigInteger& x) {
59     string s;
60     if (!(in >>s)) return in;
61     x = s;
62     return in;
63 }
64     
65 ostream& operator <<(ostream &out, BigInteger&bi) {
66     out << bi.s.back();
67     for (int i = bi.s.size()-2; i >= 0; i--) {//鍐嶄粠鍊掓暟絎簩涓緭鍑?nbsp;
68         char buf[20];
69         sprintf(buf, "%08d", bi.s[i]);
70         //cout << buf;
71         for (int j =0; j < strlen(buf); j++) out << buf[j];
72     }
73     return out;
74 }
75 
76 int main() {
77     int n;
78     BigInteger a,b,c;
79     cin >> n;
80     int kase = 1;
81     while (n) {
82         cin >> a >> b;
83         c = a + b;
84         if (n != 1)
85            cout <<"Case " << kase++ << ":" << "\n" << a << " + " << b << " = " << c << endl << endl;
86         else
87            cout <<"Case " << kase++ << ":" << "\n" << a << " + " << b << " = " << c << endl;
88         n--;
89     }
90     return 0;
91 }
錛?錛夛紙2錛夌暐銆?br />錛?錛夊垎鍧楀鐞嗙殑鍧戯細
鍓嶉潰涓や釜鎴戝氨涓嶆葷粨浜嗭紝榪欓噷涓昏璇翠笅錛屽垎鍧楄綆楃殑鍧戙傚亣璁炬湁榪欎釜瀛楃涓?123400000001"錛岀敱浜庢垜浠灝嗗叾
鎸夌収娌?浣嶅瓧絎﹀垎鎴愪竴鍧楁墍浠ョ涓鍧楀氨鏄?0000001銆佺浜屽揩灝辨槸1234錛岀劧鍚庢寜鐓у皬绔瓨鍌ㄦ牸寮忋佷綆鍦板潃瀵瑰簲浣庝綅
浣嗘槸浣嗕粬浠敤sscanf鏍煎紡鍖栨垚鏁存暟鏃跺欙紝00000001涓嶅彲鑳借繕鏄繖鏍鳳紝榪欐牱灝辨槸鍏繘鍒朵簡錛岃屾槸鍙樻垚浜?錛屾墍浠ユ垜浠?br />鍦ㄨ緭鍑虹殑鏃跺欙紝闄や簡鏈楂樹綅瀵瑰簲鐨勯偅涓鍧楀彲鑳戒笉瓚?浣嶏紝鍓╀笅鐨勫潡鑲畾閮借8浣嶅鐞嗭紝鎵浠ヤ笂闈唬鐮侊紝鎵嶄粠絎簩蹇繘琛?br />杈撳嚭錛岃屼笖鏍煎紡鏄?08d.

swp 2014-09-04 14:56 鍙戣〃璇勮
]]>
涓浜涘父璇?/title><link>http://www.shnenglu.com/sixleaves/archive/2014/08/02/207894.html</link><dc:creator>swp</dc:creator><author>swp</author><pubDate>Fri, 01 Aug 2014 21:00:00 GMT</pubDate><guid>http://www.shnenglu.com/sixleaves/archive/2014/08/02/207894.html</guid><wfw:comment>http://www.shnenglu.com/sixleaves/comments/207894.html</wfw:comment><comments>http://www.shnenglu.com/sixleaves/archive/2014/08/02/207894.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/sixleaves/comments/commentRss/207894.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/sixleaves/services/trackbacks/207894.html</trackback:ping><description><![CDATA[闂板勾璁版硶:<br />      鍥涘勾涓闂?鐧懼勾涓嶉棸,鍥涚櫨騫村啀闂?x % 4  == 0 && x %100 != 0 || x % 400 == 0)<img src ="http://www.shnenglu.com/sixleaves/aggbug/207894.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/sixleaves/" target="_blank">swp</a> 2014-08-02 05:00 <a href="http://www.shnenglu.com/sixleaves/archive/2014/08/02/207894.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍏充簬澶ф暟綆楁硶鐨勬葷粨http://www.shnenglu.com/sixleaves/archive/2014/07/24/207767.htmlswpswpWed, 23 Jul 2014 18:58:00 GMThttp://www.shnenglu.com/sixleaves/archive/2014/07/24/207767.htmlhttp://www.shnenglu.com/sixleaves/comments/207767.htmlhttp://www.shnenglu.com/sixleaves/archive/2014/07/24/207767.html#Feedback0http://www.shnenglu.com/sixleaves/comments/commentRss/207767.htmlhttp://www.shnenglu.com/sixleaves/services/trackbacks/207767.html 澶ф暟鍔犳硶鏄竴欏瑰崄鍒嗗崄鍒嗗熀鏈殑緙栫▼鎶鑳斤紝濂介笩涓嶅暟鍡﹂笩銆?br />
綆楁硶鏍稿績鎬濇兂錛?.灝嗗瓧絎︿覆鎸夌収鏉冮噸杞崲涓烘暣鍨嬫暟緇勪腑鐩稿簲鐨勪綅(0绱㈠紩瀵瑰簲鏈浣庝綅錛屾潈閲嶄負1錛屾槸涓綅)銆?.鐒跺悗榪涜鎸夌収浣嶇浉鍔犺繍綆椼?br />
鍏蜂綋浠g爜濡備笅銆?br />
 2 //  main.cpp
 3 //  oj
 4 //
 5 //  Created by sixleaves on 14-7-23.
 6 //  Copyright (c) 2014騫?nbsp;sixleaves. All rights reserved.
 7 //
 8 
 9 #include <iostream>
10 #include <string>
11 #include <cstdlib>
12 const int ArSize = 1024;
13 using namespace std;
14 char *psResult = new char[ArSize];//   鍒嗛厤浜庡爢涓紝涓嶆槸灞閮ㄥ彉閲?/span>
15 char* sum(string a, string b);

16 int main(int argc, const char * argv[])
17 {
18 
19     int nTestCase;
20     int i = 0;
21     cin >> nTestCase;
22     while (i < nTestCase) {
23         string a,b;
24         while (cin >> a >> b) {
25             cout << "Case " << i + 1 <<":"<< endl;
26             cout << a + " + " + b + " = "
27                  <<sum(a, b) << endl;
28             if(i + 1 != nTestCase)
29                 cout << endl;
30             i++;
31             break;
32         }
33     }
34     return 0;
35 }
36 
37 char* sum(string a, string b) {
38     //   榪涜鏁版嵁鐨勮漿鎹紝鎶婂瓧絎︿覆鏁版嵁杞崲涓烘暣鏁?/span>
39     //   char *psResult = new char[ArSize];
        //   涓轟簡鎻愰珮紼嬪簭閫熷害錛屾妸榪欎釜鏀懼湪浜嗗闈紝涓嶇敤姣忔閮界敵璇?/span>
40     int nR[ArSize] = {0}, nA[ArSize] = {0}, nB[ArSize] = {0};//   騫朵笖閮藉垵濮嬪寲涓?
41     int nLenA = a.length(), nLenB = b.length();
42     for(int i = 0; i < nLenA; i++) {
43         nA[i] = a[nLenA - i - 1] - '0';
44     }
45     for(int i = 0; i < nLenB; i++) {
46         nB[i] = b[nLenB - i - 1] - '0';
47     }
48     //   榪涜鐩稿姞榪愮畻
49     int nLenMax = nLenA > nLenB? nLenA : nLenB;
50     for(int i = 0; i < nLenMax; i++) {
51         nR[i] += nA[i] + nB[i];
52         if(nR[i] > 9) {
53             nR[i] -= 10;
54             nR[i + 1]++;
55         }
56     }
57     //   杞崲涓哄瓧絎︿覆
58     if(nR[nLenMax] != 0)//   濡傛灉鏈鍚庝竴浣嶇浉鍔犳湁榪戜綅錛屽垯鎬婚暱搴﹀姞1
59         nLenMax++;
60     for(int i = 0; i < nLenMax; i++) {
61         psResult[i] = nR[nLenMax - i - 1] + '0';
62     }
63     psResult[nLenMax] = '\0';
64     return psResult;
65 }
66 


swp 2014-07-24 02:58 鍙戣〃璇勮
]]>
亚洲成色www久久网站夜月| 久久久免费观成人影院| 久久久一本精品99久久精品66| 日韩精品久久无码人妻中文字幕| 一本久久久久久久| 国产精品久久久久久久久久免费| 亚洲色欲久久久久综合网| 亚洲级αV无码毛片久久精品| 国产精品久久久久影院嫩草| 久久精品国产欧美日韩| 一本久久知道综合久久| 久久精品9988| 国内精品伊人久久久久妇| 久久亚洲春色中文字幕久久久 | 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久久亚洲欧洲日产国码二区| 国产成人久久777777| 99精品久久久久久久婷婷| 色偷偷888欧美精品久久久| 香蕉久久久久久狠狠色| 一级做a爰片久久毛片人呢| 国产一区二区久久久| 国产AⅤ精品一区二区三区久久| 97精品伊人久久久大香线蕉| 国产午夜电影久久| 久久精品国产亚洲AV嫖农村妇女| 亚洲午夜精品久久久久久人妖| 一本色综合久久| 久久精品无码一区二区三区免费 | 国产精品热久久毛片| 久久久久99精品成人片欧美| 天天综合久久一二三区| 亚洲国产精品婷婷久久| 久久ww精品w免费人成| 99久久精品国产一区二区| 久久青青国产| 国内精品久久久久久久影视麻豆| 精品国产乱码久久久久久1区2区| 久久这里只有精品首页| 亚洲国产精品成人久久蜜臀| 久久精品国产第一区二区|