sudo su root -- 可以用ROOT為身份執行。
ifconfig -- 可以查IP。
dhclient -- 可以用DHCP的方式自動取得IP。
2011年8月17日 星期三
2011年8月16日 星期二
UVA 102
最近決定奮發一下,開始寫UVA的題目。
一步一步慢慢挑戰XD
第一題:102Ecological Bin Packing
結果...................狂RE....................
後來去了高中生解題的地方........WA..............
上網找了一下別人寫的答案
一步一步慢慢挑戰XD
第一題:102Ecological Bin Packing
結果...................狂RE....................
後來去了高中生解題的地方........WA..............
上網找了一下別人寫的答案
| /** |
| * UVa 102 Ecological Bin Packing (AC) |
| * Author: http://chchwy.blogspot.com |
| * Last Modified: 2008/09/10 |
| */ |
| #include<iostream> |
| enum{ B=0, C=1, G=2 }; |
| int main() |
| { |
| //六種排列組合 |
| int binColor[][3]={ {B,C,G}, {B,G,C}, {C,B,G}, |
| {C,G,B}, {G,B,C}, {G,C,B} }; |
| char s[][4]={"BCG","BGC","CBG","CGB","GBC","GCB"}; |
| int bin[3][3]; |
| while(scanf("%d%d%d%d%d%d%d%d%d", |
| &bin[0][B],&bin[0][G],&bin[0][C], |
| &bin[1][B],&bin[1][G],&bin[1][C], |
| &bin[2][B],&bin[2][G],&bin[2][C])!=EOF) |
| { |
| int currentMove=0; |
| int totalGlasses=0; |
| for(int i=0;i<3;i++) |
| totalGlasses += (bin[i][B] + bin[i][G] + bin[i][C]); |
| int minMove = totalGlasses; |
| int minNo = 0; //第minNo號排列組合move最少 |
| //六種排列組合都跑過一次 |
| for(int i=0;i<6;i++){ //移動的次數 = 總瓶數-不用移動的瓶數 |
| currentMove = totalGlasses |
| - bin[0][binColor[i][0]] |
| - bin[1][binColor[i][1]] |
| - bin[2][binColor[i][2]]; |
| if(currentMove<minMove){ |
| minMove = currentMove; |
| minNo=i; |
| } |
| } |
| printf("%s %d\n",s[minNo],minMove); |
| } |
| return 0; |
} 再看看我最後終於對的答案 #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int x,y,z,min,i, nowV; int xyzV[9],minV[3]; char *tok, represent[3] = {'B', 'G', 'C'}; min = 100000000; while( scanf(" %d %d %d %d %d %d %d %d %d", &xyzV[0], &xyzV[1], &xyzV[2], &xyzV[3], &xyzV[4], &xyzV[5], &xyzV[6], &xyzV[7], &xyzV[8]) == 9 ) { /*tok = strtok(tmp, " "); //while(tok != NULL) {*/ /*sscanf( tmp, " %d %d %d %d %d %d %d %d %d", &xyzV[0], &xyzV[1], &xyzV[2], &xyzV[3], &xyzV[4], &xyzV[5], &xyzV[6], &xyzV[7], &xyzV[8]);*/ /*printf("%d", xyzV[i]);*/ /*}*/ for( x=0 ; ; ) { nowV = 0; nowV = nowV + xyzV[0] + xyzV[1] +xyzV[2] - xyzV[x]; for( y=0 ; ; ) { if( y == x ) { y += 2; y %= 3; if( y == 0 ) break; continue; } nowV = nowV + xyzV[3] + xyzV[4] + xyzV[5] - xyzV[y+3]; for( z=0 ; ; ) { if( z == x || z == y ) { z += 2; z %= 3; if( z == 0 ) break; continue; } nowV = nowV + xyzV[6] + xyzV[7] + xyzV[8] - xyzV[z+6]; if( nowV < min ) { min = nowV; minV[0] = x; minV[1] = y; minV[2] = z; } nowV = nowV - xyzV[6] - xyzV[7] - xyzV[8] + xyzV[z+6]; z+=2; z%=3; if( z == 0 ) break; } nowV = nowV - xyzV[3] - xyzV[4] - xyzV[5] + xyzV[y+3]; y+=2; y%=3; if( y == 0 ) break; } x+=2; x%=3; if( x == 0 ) break; } printf("%c%c%c %d\n", represent[minV[0]], represent[minV[1]], represent[minV[2]], min); min = 1000000000; } return 0; } 真的是弱慘了我............ 紅色部分的就是導致我WA的兇手(忘了還要再扣然後才能再算下個結果)............ |
訂閱:
意見 (Atom)