Skip to content

Commit 1bae410

Browse files
author
coderxiang
committed
CF 204
1 parent 13b7816 commit 1bae410

File tree

131 files changed

+222
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+222
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

Codeforces/204/351A_204.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
#include <string>
5+
#include <list>
6+
#include <set>
7+
#include <map>
8+
#include <sstream>
9+
#include <algorithm>
10+
#include <cstring>
11+
#include <cmath>
12+
#include <ctime>
13+
#include <cstdio>
14+
#include <cassert>
15+
16+
using namespace std;
17+
18+
typedef long long ll;
19+
typedef pair<int,int> PII;
20+
typedef vector<int> VI;
21+
typedef vector<string> VS;
22+
#define pb push_back
23+
#define mp make_pair
24+
#define ff first
25+
#define ss second
26+
#define sz(v) (int)v.size()
27+
#define clr(x, v) memset(x, v, sizeof(x))
28+
#define rep(i, l, u) for(int i = (l); i < (u); i++)
29+
#define repv(i, v) for(i = 0; i < (int)v.size(); i++)
30+
#define repi(it, c) for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
31+
32+
33+
const int N = 100011;
34+
35+
int main () {
36+
int i, j, k, n, cnt = 0;
37+
int sum = 0;
38+
scanf ("%d", &n);
39+
for (i = 1; i <= 2 * n; ++i) {
40+
scanf ("%d.%d", &j, &k);
41+
sum -= k;
42+
cnt += k == 0;
43+
}
44+
sum += 1000 * n;
45+
int mi = max(0, cnt - n), ma = min(cnt, n);
46+
int ans = 100000000;
47+
for (i = mi; i <= ma; ++i)
48+
ans = min(ans, abs(sum - i * 1000));
49+
printf ("%.3lf\n", (double)ans / 1000.0);
50+
}
51+

Codeforces/204/351B_204.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
#include <string>
5+
#include <list>
6+
#include <set>
7+
#include <map>
8+
#include <sstream>
9+
#include <algorithm>
10+
#include <cstring>
11+
#include <cmath>
12+
#include <ctime>
13+
#include <cstdio>
14+
#include <cassert>
15+
16+
using namespace std;
17+
18+
typedef long long ll;
19+
typedef pair<int,int> PII;
20+
typedef vector<int> VI;
21+
typedef vector<string> VS;
22+
#define pb push_back
23+
#define mp make_pair
24+
#define ff first
25+
#define ss second
26+
#define sz(v) (int)v.size()
27+
#define clr(x, v) memset(x, v, sizeof(x))
28+
#define rep(i, l, u) for(int i = (l); i < (u); i++)
29+
#define repv(i, v) for(i = 0; i < (int)v.size(); i++)
30+
#define repi(it, c) for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
31+
32+
33+
const int N = 100011;
34+
int a[N], n;
35+
36+
int main () {
37+
int i, j, k, inv = 0;
38+
scanf ("%d", &n);
39+
for (i = 1; i <= n; ++i)
40+
scanf ("%d", &a[i]);
41+
for (i = 1; i <= n; ++i)
42+
for (j = i + 1; j <= n; ++j)
43+
inv += a[i] > a[j];
44+
45+
if (inv == 0) printf ("0\n");
46+
else if (inv == 1) printf ("1\n");
47+
else {
48+
int pp = 0, p = 1;
49+
for (i = 2; i <= inv; ++i) {
50+
k = pp + 4;
51+
pp = p; p = k;
52+
}
53+
printf ("%d\n", k);
54+
}
55+
return 0;
56+
}
57+

Codeforces/204/352A_204.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
#include <string>
5+
#include <list>
6+
#include <set>
7+
#include <map>
8+
#include <sstream>
9+
#include <algorithm>
10+
#include <cstring>
11+
#include <cmath>
12+
#include <ctime>
13+
#include <cstdio>
14+
#include <cassert>
15+
16+
using namespace std;
17+
18+
typedef long long ll;
19+
typedef pair<int,int> PII;
20+
typedef vector<int> VI;
21+
typedef vector<string> VS;
22+
#define pb push_back
23+
#define mp make_pair
24+
#define ff first
25+
#define ss second
26+
#define sz(v) (int)v.size()
27+
#define clr(x, v) memset(x, v, sizeof(x))
28+
#define rep(i, l, u) for(int i = (l); i < (u); i++)
29+
#define repv(i, v) for(i = 0; i < (int)v.size(); i++)
30+
#define repi(it, c) for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
31+
32+
33+
const int N = 100011;
34+
35+
int main () {
36+
int i, j, k, n, c0 = 0, c5 = 0;
37+
scanf ("%d", &n);
38+
for (i = 1; i <= n; ++i) {
39+
scanf ("%d", &j);
40+
if (j == 0) c0 ++;
41+
else c5++;
42+
}
43+
if (!c0) printf("-1\n");
44+
else {
45+
c5 = (c5 * 5/45*45)/5;
46+
if (c5 == 0) printf ("0\n");
47+
else {
48+
while(c5--) printf("5");
49+
while(c0--) printf("0");
50+
}
51+
}
52+
return 0;
53+
}

Codeforces/204/352B_204.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
#include <string>
5+
#include <list>
6+
#include <set>
7+
#include <map>
8+
#include <sstream>
9+
#include <algorithm>
10+
#include <cstring>
11+
#include <cmath>
12+
#include <ctime>
13+
#include <cstdio>
14+
#include <cassert>
15+
16+
using namespace std;
17+
18+
typedef long long ll;
19+
typedef pair<int,int> PII;
20+
typedef vector<int> VI;
21+
typedef vector<string> VS;
22+
#define pb push_back
23+
#define mp make_pair
24+
#define ff first
25+
#define ss second
26+
#define sz(v) (int)v.size()
27+
#define clr(x, v) memset(x, v, sizeof(x))
28+
#define rep(i, l, u) for(int i = (l); i < (u); i++)
29+
#define repv(i, v) for(i = 0; i < (int)v.size(); i++)
30+
#define repi(it, c) for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
31+
32+
33+
const int N = 100011;
34+
35+
int p[N], n;
36+
int pos[N];
37+
38+
int main () {
39+
int i, j, k;
40+
scanf ("%d", &n);
41+
memset (pos, -1, sizeof(pos));
42+
for (i = 1; i <= n; ++i) {
43+
scanf ("%d", &j);
44+
if (pos[j] == -2) continue; // not valid
45+
if (pos[j] == -1) {pos[j] = i; p[j] = 0;} // first time
46+
else if (p[j] == 0) {p[j] = i - pos[j]; pos[j] = i;} // second time
47+
else {
48+
if (i - pos[j] != p[j]) pos[j] = -2;
49+
else pos[j] = i;
50+
}
51+
}
52+
k = 0;
53+
for (i = 1; i <= 100000; ++i)
54+
if (pos[i] >= 0) k ++;
55+
printf ("%d\n", k);
56+
for (i = 1; i <= 100000; ++i)
57+
if (pos[i] != -2 && pos[i] != -1)
58+
printf ("%d %d\n", i, p[i]);
59+
60+
return 0;
61+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)