2016年5月29日 星期日
Uva 11039 Building designing
題目來源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1980
2016年5月28日 星期六
Uva 167 The Sultan's Successors
#八皇后 #The Sultan's Successors #Uva167
題目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=103
題目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=103
算是八皇后問題之一,只是一直錯在遞迴的地方...昨天一直debug不出來...
寫這題的時候,順便回去複習了一下八皇后
======================八皇后解法======================
先橫向逐行放置皇后
將位置存至M[ i ] = j;
表示第 i 行的 的皇后在第 j 列
======================八皇后解法======================
先橫向逐行放置皇后
將位置存至M[ i ] = j;
表示第 i 行的 的皇后在第 j 列
2016年5月5日 星期四
uva 10474 Where is the Marble?
題目來源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1415
程式碼:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
int N,Q,a[10000],x,ptr,times = 1; | |
while(scanf("%d %d",&N,&Q)==2 && (N || Q)){ | |
for(int i = 0;i<N;i++) | |
scanf("%d",&a[i]); | |
sort(a,a+N);//排序 | |
printf("CASE# %d:\n",times++); | |
while(Q--){ | |
scanf("%d",&x); | |
ptr = lower_bound(a,a+N,x)-a; | |
//如果有找到 | |
if(a[ptr]==x) printf("%d found at %d\n",x,ptr+1); | |
//如果沒找到 | |
else printf("%d not found\n",x); | |
} | |
} | |
} |
2016年5月4日 星期三
uva 11207 The easiest way
題目來源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2148
程式碼:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
using namespace std; | |
struct P{ | |
double a,b; | |
double c; | |
}p[100001]; | |
int main(){ | |
int T,Min; | |
while(cin>>T && T){ | |
Min = 0; | |
for(int i=0;i<T;i++){ | |
cin>>p[i].a>>p[i].b; | |
if(p[i].a<p[i].b) swap(p[i].a,p[i].b); | |
if(p[i].b*4<=p[i].a) { | |
p[i].c = p[i].b; | |
} | |
else{ | |
p[i].c=max(p[i].b/2,p[i].a/4); | |
} | |
if(p[i].c>p[Min].c) Min = i; | |
} | |
cout<<Min+1<<endl; | |
} | |
} |
Uva 443 Humble Numbers
題目來源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=384
這一題在luckycat上有中文翻譯,剛開始看完題目的時候,是用遞迴寫的,但一直跑無窮迴圈@@,最後用了BFS的方法寫,把要處理的元素放入queue中,當queue裡面沒有元素的時候,就會跳出迴圈,這次也學會了一些vector小技巧
因為只要找質因數只有2 3 5 7的數字,那就把2 3 5 7一直乘一直乘就好了吧(?)
但是也不知道要怎麼乘才不會亂掉,最後想到把要乘得數字放入queue中,然後每次都從queue中拿出元素(以下稱t),讓t和 2 3 5 7 相乘,乘出來的元素在放入queue中,還有vector中,但如果t之前有放過了(因為2*5==5*2會有元素重複問題),就不用再放了,最後將vector由小到大排序,程式就大致完成了
這一題在luckycat上有中文翻譯,剛開始看完題目的時候,是用遞迴寫的,但一直跑無窮迴圈@@,最後用了BFS的方法寫,把要處理的元素放入queue中,當queue裡面沒有元素的時候,就會跳出迴圈,這次也學會了一些vector小技巧
因為只要找質因數只有2 3 5 7的數字,那就把2 3 5 7一直乘一直乘就好了吧(?)
但是也不知道要怎麼乘才不會亂掉,最後想到把要乘得數字放入queue中,然後每次都從queue中拿出元素(以下稱t),讓t和 2 3 5 7 相乘,乘出來的元素在放入queue中,還有vector中,但如果t之前有放過了(因為2*5==5*2會有元素重複問題),就不用再放了,最後將vector由小到大排序,程式就大致完成了
訂閱:
文章 (Atom)