跳到主要內容

發表文章

UVA 10004

UVA 10004 : https://uva.onlinejudge.org/external/100/10004.pdf /*DFS , bipartite graph*/ #include<iostream> #include<cstring> using namespace std; #define size 205 int matrix[size][size]; int color[size]; int n = 0; int dfs(int start) { for (int end= 0; end < n; end++) { //matirx[start][end] = 1 , means start vertex and end vertex was connected if (matrix[start][end]) { //if end vertex hasn't be check, then drew color and keep going next adjacent vertex if (!color[end]) { color[end] = !color[start]; dfs(end); } // based on end vertex has been check before // start vertex and end vertex color have the same color, means color already repeat ,so cant be drew correct else if (color[start] == color[end]) return 0; } } return 1; } int main(void) { while (1) { int l = 0,row=0,col=0; cin >> n; if (n == 0)break; cin >> l; memset(matrix, 0, sizeof(matrix));
最近的文章

UVA11547

UVA 11547 : https://uva.onlinejudge.org/external/115/11547.pdf #include<iostream> using namespace std; int t = 0,n=0; int main(void) { cin >> t; while (t--) { cin >> n; n = n* 315+36962; cout << abs(n/10%10) << endl; } system("PAUSE"); }

UVA 488

UVA488 : https://uva.onlinejudge.org/external/4/488.pdf /*easy */ #include<iostream> using namespace std; int n = 0,A = 0,F = 0,blank=1; int main(void) { cin >> n; while(n--) { cin >> A >> F; for (int f = 0; f < F; f++) { int i = 1, j = 1; if (blank == 0)cout << endl; for (i = 1; i <= A; i++) { for (j = 1; j <= i; j++) { cout << i; } cout << endl; } for (i = A - 1; i >= 1; i--) { for (int j = i; j >= 1; j--) { cout << i ; } cout << endl; } blank = 0; } } system("PAUSE"); }

UVA 10696

UVA 10696 :     https://uva.onlinejudge.org/external/106/10696.pdf /*recurrsion math*/ #include<iostream> #include<cstring> using namespace std; int n=0,ans=0; int main(void) { while (cin >> n) { if (n == 0)break; //regular if (n <= 101) ans = 91; else ans = n - 10; cout <<"f91("<<n<<") = "<< ans << endl; } system("PAUSE"); }

UVA 108

UVA 108:  https://uva.onlinejudge.org/external/1/108.pdf /*Maximum Subarray*/ /* normal : O(N^4) best : O(N^3) */ reference #include<iostream> #include<cstring> #include<algorithm> #define maxn 100+5 using namespace std; int n, matrix[maxn][maxn], cur_matrix[maxn]; int find_max() { //calculate maximum subarray each row int cur_sum = 0, sum = 0; for (int l = 0; l < n; l++) { sum += cur_matrix[l]; cur_sum = max(sum, cur_sum); if (sum < 0) sum = 0; } return cur_sum; } void ans() { //compress int MaxSum = -200; for (int i = 0; i < n; i++) { memset(cur_matrix, 0, sizeof(cur_matrix)); for (int j = i; j < n; j++) { for (int k = 0; k < n; k++) { cur_matrix[k] += matrix[j][k]; } MaxSum = max(MaxSum, find_max()); } } cout << MaxSum << endl; } int main(void) { while (cin >> n) { for (int i = 0; i < n; i++) { for (int j = 0; j <

UVA113

UVA113  :   https://uva.onlinejudge.org/external/1/113.pdf /*math*/ /* based on : k n = p (k n ) (1/n) = p (1/n) k = p (1/n) /* k = pow(p,1/n) */ reference */ #include <iostream> #include <stdlib.h> #include <math.h> using namespace std; int main() { // your code goes here double n, p,k; while (cin>>n>>p) { k = pow(p, 1.0 / n); /* Most probably the default number digit after decimal is 6, so in UVA compiler your ans.                     for 2 16 would be 4.000000 and not 4.                                                                                                     reference */ printf("%.0lf\n", k); } system("PAUSE"); }

UVA 10474

UVA 10474 :  https://uva.onlinejudge.org/external/104/10474.pdf /*sort*/ #include <iostream> #include<string.h> #include <algorithm> using namespace std; int main() { // your code goes here int n=0,q=0; int count = 1; while(cin>>n>>q) { if(n==0&&q==0)break; cout<<"CASE# "<<count<<":"<<endl; int num[n];memset(num,0,sizeof(num)); int inquire[q];memset(inquire,0,sizeof(q)); for(int i=0;i<n;i++) { cin>>num[i]; } sort(num,num+n); for(int in=0;in<q;in++) { cin>>inquire[in]; } for(int j =0;j<q;j++) { int check =0; for(int k=0;k<n&&check==0;k++) { if(num[k]==inquire[j]) { check =1; cout<<inquire[j]<<" found at "<<++k<<endl; } } if(check==0) cout<<inquire[j]<<" not found&quo