Apr 19, 2011.
Accepted: 3. WA: 0. NotTried: 2.
Tutorial
Problem 1:
Solution:
Could check every number from n+1,
if that number is a prime and also equals to m, then "YES".
else "NO";
Source Code:
//Tuesday, April 19, 2011 09:37 CDT
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
bool isPrime(int n) {
if (n % 2 == 0 && n != 2)
return false;
if (n == 2)
return true;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
bool check(int n, int m) {
int i;
for (i = n + 1;; i++)
if (isPrime(i))
break;
return i == m;
}
int main(int argc, char* argv[]) {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m;
cin >> n >> m;
if (check(n, m))
cout << "YES" << endl;
else
cout << "NO" << endl;
//fclose(stdin);
//fclose(stdout);
return 0;
}
Problem 2:
Solution:
Easy Math problem, remember to check hour to make sure that's smaller than 12.
Source Code:
//Tuesday, April 19, 2011 09:37 CDT
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
pair<double, double> solve(int h, int m) {
h %= 12;
double mm = 6.0 * m;
double hh = 30.0 * h + 1.0 * m * 30.0 / 60.0;
return make_pair(hh, mm);
}
int main(int argc, char* argv[]) {
// freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int h, m;
char c;
cin >> h >> c >> m;
pair<double, double> display = solve(h, m);
cout << display.first << " " << display.second << endl;
// fclose(stdin);
//fclose(stdout);
return 0;
}
Problem 3:
Solution:
Source Code:
Problem 4:
Solution:
Source Code:
//Tuesday, April 19, 2011 09:37 CDT
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
double solve(double a, double b) {
if (b == 0)
return 1.0;
if (a == 0)
return 0.5;
if (4.0 * b > a) {
return (0.5 + a / b / 16.0);
} else
return (1.0 - b / a);
}
int main(int argc, char* argv[]) {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
cin >> T;
while (T--) {
double a, b;
cin >> a >> b;
cout << solve(a, b) << endl;
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
Problem 5:
Solution:
Source Code:
if that number is a prime and also equals to m, then "YES".
else "NO";
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
bool isPrime(int n) {
if (n % 2 == 0 && n != 2)
return false;
if (n == 2)
return true;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
bool check(int n, int m) {
int i;
for (i = n + 1;; i++)
if (isPrime(i))
break;
return i == m;
}
int main(int argc, char* argv[]) {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m;
cin >> n >> m;
if (check(n, m))
cout << "YES" << endl;
else
cout << "NO" << endl;
//fclose(stdin);
//fclose(stdout);
return 0;
}
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
pair<double, double> solve(int h, int m) {
h %= 12;
double mm = 6.0 * m;
double hh = 30.0 * h + 1.0 * m * 30.0 / 60.0;
return make_pair(hh, mm);
}
int main(int argc, char* argv[]) {
// freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int h, m;
char c;
cin >> h >> c >> m;
pair<double, double> display = solve(h, m);
cout << display.first << " " << display.second << endl;
// fclose(stdin);
//fclose(stdout);
return 0;
}
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
double solve(double a, double b) {
if (b == 0)
return 1.0;
if (a == 0)
return 0.5;
if (4.0 * b > a) {
return (0.5 + a / b / 16.0);
} else
return (1.0 - b / a);
}
int main(int argc, char* argv[]) {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
cin >> T;
while (T--) {
double a, b;
cin >> a >> b;
cout << solve(a, b) << endl;
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
No comments :
Post a Comment