Permalink
Browse files

Add more uva

  • Loading branch information...
1 parent 1412556 commit c31d0446df5eaf78c2909f953c8527440a34e4e8 @sirupsen committed Aug 2, 2012
View
@@ -0,0 +1,48 @@
+#include<iostream>
+#include<vector>
+#include<algorithm>
+#include<cstdio>
+#include<cassert>
+using namespace std;
+
+int main()
+{
+ bool first = true;
+ int zero = 0;
+
+ while(true) {
+ int f, r, ft[101], rt[101];
+ vector<double> ratios;
+
+ cin >> f;
+ if (f == 0) break;
+
+ cin >> r;
+
+ for(int i = 0; i < f; i++) cin >> ft[i];
+ for(int i = 0; i < r; i++) cin >> rt[i];
+
+ // outer loop on the longest
+ for(int i = 0; i < f; i++)
+ for(int j = 0; j < r; j++)
+ ratios.push_back(((double) rt[j])/((double) ft[i]));
+
+ sort(ratios.begin(), ratios.end());
+
+ vector<double>::iterator it;
+ double prev = ratios[0];
+ double max_spread = 0;
+
+ for(it = ratios.begin() + 1; it != ratios.end(); it++) {
+ double spread = *it / prev;
+ if(spread > max_spread) max_spread = spread;
+ prev = *it;
+ }
+
+ printf("%.2f\n", max_spread);
+
+ first = false;
+ }
+
+ return 0;
+}
View
Binary file not shown.
View
@@ -0,0 +1,2 @@
+1.19
+1.19
View
@@ -0,0 +1,73 @@
+#include<iostream>
+#include<algorithm>
+#include<cstdio>
+#include<cstdlib>
+#include<cmath>
+using namespace std;
+
+struct Constraint {
+ int first_person;
+ int second_person;
+ int constraint;
+};
+
+int n_persons, n_constraints;
+
+bool satisfies_condition(int arrangement[], Constraint condition)
+{
+ int first_person_index;
+ for(int i = 0; i < n_persons; i++)
+ if(arrangement[i] == condition.first_person) first_person_index = i;
+
+ int second_person_index;
+ for(int i = 0; i < n_persons; i++)
+ if(arrangement[i] == condition.second_person) second_person_index = i;
+
+ int difference = abs(first_person_index - second_person_index);
+ // cout << difference << endl;
+
+ if (condition.constraint < 0) {
+ return abs(condition.constraint) <= difference;
+ } else {
+ return abs(condition.constraint) >= difference;
+ }
+}
+
+int main()
+{
+ while(scanf("%d %d", &n_persons, &n_constraints) == 2) {
+ Constraint conditions[22];
+
+ if(n_persons == 0 && n_constraints == 0) return 0;
+
+ for(int i = 0; i < n_constraints; i++) {
+ int person_1, person_2, constraint;
+ scanf("%d %d %d", &person_1, &person_2, &constraint);
+
+ Constraint condition = {person_1, person_2, constraint};
+ conditions[i] = condition;
+ }
+
+ int permute_me[21];
+ int count = 0;
+
+ for(int i = 0; i < n_persons; i++)
+ permute_me[i] = i;
+
+ do {
+ // for(int i = 0; i < n_persons; i++)
+ // cout << permute_me[i];
+ // cout << endl;
+
+ bool all = true;
+ for(int i = 0; i < n_constraints; i++)
+ if (!satisfies_condition(permute_me, conditions[i])) all = false;
+
+ if(all) count++;
+ } while (next_permutation(permute_me, permute_me + n_persons));
+
+ cout << count << endl;
+ }
+
+ return 0;
+}
View
Binary file not shown.
View
@@ -0,0 +1,2 @@
+2
+6
View
@@ -0,0 +1,18 @@
+#include<iostream>
+#include<algorithm>
+using namespace std;
+
+int main()
+{
+ int length = 4;
+ int numbers[] = {0,1,2,3};
+
+ do {
+ for(int i = 0; i < length; i++)
+ cout << numbers[i];
+
+ cout << endl;
+ } while (next_permutation(numbers, numbers + length));
+
+ return 0;
+}
View
@@ -0,0 +1,24 @@
+0123
+0132
+0213 x
+0231 x
+0312 x
+0321 x
+1023
+1032
+1203 x
+1230 x
+1302 x
+1320 x
+2013
+2031 x
+2103
+2130 x
+2301
+2310
+3012
+3021 x
+3102
+3120 x
+3201
+3210
@@ -0,0 +1,51 @@
+ #include<iostream>
+ using namespace std;
+
+ void substrings(string main_string, int substring_length)
+ {
+ for(int i = 0; i < substring_length; i++) {
+ for(int j = i; j < substring_length; j++) {
+ for(int k = i; k <= j; k++)
+ cout << main_string[k];
+
+ cout << endl;
+ }
+ }
+ }
+
+ string remove_duplicates(string subject)
+ {
+ string no_duplicates("");
+
+ for(int i = 0; i < subject.length(); i++) {
+ bool found = false;
+
+ for(int j = 0; j < no_duplicates.length(); j++) {
+ if (no_duplicates[j] == subject[i]) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) no_duplicates += subject[i];
+ }
+
+ return no_duplicates;
+ }
+
+ int n_substrings(int substring_length)
+ {
+ return (substring_length * (substring_length + 1)) / 2;
+ }
+
+ int main()
+ {
+ string alphabet("abcdefghijklmnopqrstuvwxyz");
+ string hello("hello there");
+
+ substrings(alphabet, 5);
+ cout << n_substrings(5) << endl;
+ substrings(remove_duplicates(hello), 5);
+
+ return 0;
+ }
@@ -0,0 +1,34 @@
+#include<iostream>
+#include<map>
+#include<cmath>
+
+int main()
+{
+ unsigned int;
+
+ cin >> n;
+ map<int,string> short_scale;
+ map<int,string> long_scale;
+
+ short_scale[6] = "million";
+ long_scale[6] = "million";
+
+ short_scale[12] = "billion";
+ long_scale[12] = "milliard";
+
+ short_scale[12] = "trillion";
+ long_scale[12] = "billion";
+
+ short_scale[15] = "quadrillion";
+ long_scale[15] = "billiard";
+
+ short_scale[18] = "quintillion";
+ long_scale[18] = "trillion";
+
+ short_scale[21] = "sextillion";
+ long_scale[21] = "trilliard";
+
+ int zeros = log10(n);
+
+ return 0;
+}

0 comments on commit c31d044

Please sign in to comment.