A. Between the offices
Xiao Ming is an executive who travels a lot, and he will be very happy if he flies from S to f more often than from f to land.
Topic idea: Violent sweep again, note the number of SF substring and FS substring in the string, and then determine its size, you can come to an answer
Title Link: Http://codeforces.com/contest/867/problem/A
Code:
1 /* ***********************************************
2 Author: xiaowuga
3 Created Time: Monday, October 02, 2017 12:09:34
4 File Name: A.cpp
5 ************************************************ * /
6 #include <bits / stdc ++. H>
7 #define mem (s, ch) memset (s, ch, sizeof (s))
8 typedef long long LL;
9 #define inf 0x3f3f3f3f
10 const long long N = 1000000;
11 const long long mod = 1e9 + 7;
12 using namespace std;
13 int main () {
14 ios :: sync_with_stdio (false); cin.tie (0);
15 int n;
16 string q;
17 cin >> n;
18 cin >> q;
19 int c1 = 0, c2 = 0;
20 for (int i = 1; i <q.size (); i ++) {
21 if (q [i] == ‘F‘ && q [i-1] == ‘S’) c1 ++;
22 else if (q [i] == ‘S’ && q [i-1] == ‘F’) c2 ++;
twenty three }
24 if (c1> c2) cout << "YES" << endl;
25 else cout << "NO" << endl;
26 return 0;
27}
View CodeB. Save the problem!
The title means: similar to the reverse complete backpack, the past is given to make up the amount of change, and the amount of various coins, let you ask how many different combinations, now upside down, give you how many of these combinations, let you give a plan (including the amount of change, denomination, the size of various denominations)
The topic thought: MDZZ, completely relies on the bold conjecture to seek the law, looks directly the code!
Code:
1 /* ***********************************************
2 Author: xiaowuga
3 Created Time: Monday, October 02, 2017 12:09:34
4 File Name: A.cpp
5 ************************************************ * /
6 #include <bits / stdc .h>
7 #define mem (s, ch) memset (s, ch, sizeof (s))
8 typedef long long LL;
9 #define inf 0x3f3f3f3f
10 const long long N = 1000000;
11 const long long mod = 1e9 7;
12 using namespace std;
13 int main () {
14 ios :: sync_with_stdio (false); cin.tie (0);
15 int n;
16 string q;
17 cin >> n;
18 cin >> q;
19 int c1 = 0, c2 = 0;
20 for (int i = 1; i <q.size (); i) {
21 if (q [i] == ‘F‘ && q [i-1] == ‘S’) c1;
22 else if (q [i] == ‘S’ && q [i-1] == ‘F’) c2;
twenty three }
24 if (c1> c2) cout << "YES" << endl;
25 else cout << "NO" << endl;
26 return 0;
27}
View CodeC. Ordering Pizza
Title: Give N and S, say there are now n people, each pizza has s block, now give each person want to eat pizza number, and every eat a piece of type1 pizza will get a point happy value, each eat a type2 pizza will get B point happy value. Now ask in the case of buying the least pizza, if and let everyone happy value and maximum.
Topic ideas: Greedy ideas, try to let people like to eat type1 pizza type1 pizza, like to eat type2 pizza people eat type2 pizza, then we let them eat their favorite pizza, calculate how much to type1 the number of fast (P block), type2 number of blocks (blocks), Then to the S to take the film (ie p%=s,q%=s) if the p+q>s, that a pizza is not enough points, we need to buy two pieces, so it is clear that we buy two different pizza, we can meet all eat their favorite pizza, otherwise we can only buy a pizza, It means that some people can't eat their favorite pizza, and now we need to think about what kind of pizza to buy is better, in the greedy mind, we must be for two kinds of pizza like the difference is not obvious (that is, ABS (A-B) is small), can not eat their favorite pizza, This brings the loss is the smallest, and then judge let like eat type1 eat type2, or like to eat type2 eat type1 which loss more small lost on the good.
Code:
1 /* ***********************************************
2 Author: xiaowuga
3 Created Time: Monday, October 02, 2017 14:28:30
4 File Name: C.cpp
5 ************************************************ * /
6 #include <bits / stdc ++. H>
7 #define mem (s, ch) memset (s, ch, sizeof (s))
8 typedef long long LL;
9 #define inf 0x3f3f3f3f
10 const long long mod = 1e9 + 7;
11 using namespace std;
12 vector <pair <LL, LL>> v1, v2;
13 int main () {
14 ios :: sync_with_stdio (false); cin.tie (0);
15 LL N, S;
16 cin >> N >> S;
17 LL s, a, b;
18 LL ans = 0;
19 LL p = 0, q = 0;
20 // ans = total number, total number of p (a> b), total number of q (a <b)
21 for (int i = 1; i <= N; i ++) {
22 cin >> s >> a >> b;
23 if (a> b) {
24 ans + = s * a;
25 p + = s;
26 v1.push_back (make_pair (a-b, s));
27}
28 else {
29 ans + = s * b;
30 q + = s;
31 v2.push_back (make_pair (b-a, s));
32}
33}
34 p% = S; q% = S;
35 if (p + q> S) {// then buy one for type1 and one for type2
36 cout << ans << endl;
37 return 0;
38}
39 sort (v1.begin (), v1.end ());
40 sort (v2.begin (), v2.end ());
41 LL x = 0, y = 0;
42 for (auto it: v1) {
43 x + = min (it.second, p) * it.first;
44 p- = min (it.second, p);
45}
46 for (auto it: v2) {
47 y + = min (it.second, q) * it.first;
48 q- = min (it.second, q);
49}
50 cout << ans-min (x, y) << endl;
51 return 0;
52}
View Code
Codeforces Round #437 (Div. 2, based on Memsql start[c]up 3.0-round 2)