2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
Little Boxes
Little boxes made of ticky-tacky.
Little boxes.
Little boxes.
Little boxes all the same.
There are a green boxes, and b pink boxes.
And c blue boxes and d yellow boxes.
And they are all made out of ticky-tacky.
And they all look just the same.
For
each test case, a line contains four non-negative integers a, b, c and d
where a, b, c, d ≤ 2^62, indicating the numbers of green boxes, pink
boxes, blue boxes and yellow boxes.
1 2 3 4
0 0 0 0
1 0 0 0
111 222 333 404
import java.math.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
BigInteger a,b,c,d;
int T;T=cin.nextInt();
for(int i=0;i<T;i++) {
a=cin.nextBigInteger();b=cin.nextBigInteger();c=cin.nextBigInteger();d=cin.nextBigInteger();
BigInteger res=a.add(b).add(c).add(d);
System.out.println(res);
}
}
}
Rabbits
N (N ≥ 3) rabbits are playing by the river. They are playing on a
number line, each occupying a different integer. In a single move, one
of the outer rabbits jumps into a space between any other two. At no
point may two rabbits occupy the same position.
Help them play as long as possible
input has several test cases. The first line of input contains an
integer t (1 ≤ t ≤ 500) indicating the number of test cases.
For each case the first line contains the integer N (3 ≤ N ≤ 500) described as above. The second line contains n integers a1 < a2 < a3 < ... < aN which are the initial positions of the rabbits. For each rabbit, its initial position
ai satisfies 1 ≤ ai ≤ 10000.
3
3 4 6
3
2 3 5
3
3 5 9
4
1 2 3 4
4
1 2 4 5
1
3
0
1
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream> //#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++) inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}
/*
int n, m;
int st, ed;
struct node {
int u, v, nxt, w;
}edge[maxn<<1]; int head[maxn], cnt; void addedge(int u, int v, int w) {
edge[cnt].u = u; edge[cnt].v = v; edge[cnt].w = w;
edge[cnt].nxt = head[u]; head[u] = cnt++;
} int rk[maxn]; int bfs() {
queue<int>q;
ms(rk);
rk[st] = 1; q.push(st);
while (!q.empty()) {
int tmp = q.front(); q.pop();
for (int i = head[tmp]; i != -1; i = edge[i].nxt) {
int to = edge[i].v;
if (rk[to] || edge[i].w <= 0)continue;
rk[to] = rk[tmp] + 1; q.push(to);
}
}
return rk[ed];
}
int dfs(int u, int flow) {
if (u == ed)return flow;
int add = 0;
for (int i = head[u]; i != -1 && add < flow; i = edge[i].nxt) {
int v = edge[i].v;
if (rk[v] != rk[u] + 1 || !edge[i].w)continue;
int tmpadd = dfs(v, min(edge[i].w, flow - add));
if (!tmpadd) { rk[v] = -1; continue; }
edge[i].w -= tmpadd; edge[i ^ 1].w += tmpadd; add += tmpadd;
}
return add;
}
ll ans;
void dinic() {
while (bfs())ans += dfs(st, inf);
}
*/ int n;
int a[1000];
int main()
{
//ios::sync_with_stdio(0);
//memset(head, -1, sizeof(head));
int T; cin >> T;
while (T--) {
rdint(n);
for (int i = 1; i <= n; i++)rdint(a[i]);
int ans = 0;
for (int i = 2; i < n; i++) {
ans += (a[i + 1] - a[i] - 1);
}
int maxx = ans;
ans = 0;
for (int i = n - 1; i > 1; i--) {
ans += (a[i] - a[i - 1] - 1);
}
maxx = max(maxx, ans);
cout << maxx << endl;
}
return 0;
}
Heron and His Triangle
than or equal to n.
input contains multiple test cases. The first line of a multiple input
is an integer T (1 ≤ T ≤ 30000) followedby T lines. Each line contains
an integer N (1 ≤ N ≤ 10^30).
1
2
3
4
4
4
4
import java.lang.reflect.Array;
import java.math.*; import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
BigInteger N;
int T;T=cin.nextInt();
BigInteger num[]=new BigInteger[1000];
num[1]=BigInteger.valueOf(4);num[2]=BigInteger.valueOf(14);
for(int i=3;i<=500;i++)num[i]=num[i-1].multiply(BigInteger.valueOf(4)).subtract(num[i-2]);
for(int i=0;i<T;i++) {
N=cin.nextBigInteger();
for(int j=1;j<=400;j++) {
if(num[j].compareTo(N)>=0) {
System.out.println(num[j]);break;
}
}
}
} }
Tree
Now we decide to colour its nodes
with k distinct colours, labelled from 1 to k. Then for each colour i =
1, 2, · · · , k, define Ei as the minimum subset of edges connecting all
nodes coloured by i. If there is no node of the tree coloured by a
specified colour i, Ei will be empty.
Try to decide a colour scheme to maximize the size of E1 ∩ E2 · · · ∩ Ek, and output its size.
For
each case, the first line contains two positive integers n which is the
size of the tree and k (k ≤ 500) which is the number of colours. Each
of the following n - 1 lines contains two integers x and y describing an
edge between them. We are sure that the given graph is a tree.
The summation of n in input is smaller than or equal to 200000.
4 2
1 2
2 3
3 4
4 2
1 2
1 3
1 4
6 3
1 2
2 3
3 4
3 5
6 2
0
1
现在我们决定用k个不同的颜色为节点着色,标记为1到k。 然后,对于每种颜色i = 1,2,...,k,将Ei定义为连接由i着色的所有节点的边的最小子集。 如果树的节点没有由指定颜色i着色,则Ei将为空。
尝试确定一个配色方案,以最大化E1∩E2···∩Ek的大小,并输出其大小。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream> //#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 100005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++) inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}
/*
int n, m;
int st, ed;
struct node {
int u, v, nxt, w;
}edge[maxn<<1]; int head[maxn], cnt; void addedge(int u, int v, int w) {
edge[cnt].u = u; edge[cnt].v = v; edge[cnt].w = w;
edge[cnt].nxt = head[u]; head[u] = cnt++;
} int rk[maxn]; int bfs() {
queue<int>q;
ms(rk);
rk[st] = 1; q.push(st);
while (!q.empty()) {
int tmp = q.front(); q.pop();
for (int i = head[tmp]; i != -1; i = edge[i].nxt) {
int to = edge[i].v;
if (rk[to] || edge[i].w <= 0)continue;
rk[to] = rk[tmp] + 1; q.push(to);
}
}
return rk[ed];
}
int dfs(int u, int flow) {
if (u == ed)return flow;
int add = 0;
for (int i = head[u]; i != -1 && add < flow; i = edge[i].nxt) {
int v = edge[i].v;
if (rk[v] != rk[u] + 1 || !edge[i].w)continue;
int tmpadd = dfs(v, min(edge[i].w, flow - add));
if (!tmpadd) { rk[v] = -1; continue; }
edge[i].w -= tmpadd; edge[i ^ 1].w += tmpadd; add += tmpadd;
}
return add;
}
ll ans;
void dinic() {
while (bfs())ans += dfs(st, inf);
}
*/
int n;
vector<int>vc[maxn];
int Siz[maxn]; void dfs(int u, int rt) {
Siz[u] = 1;
for (int i = 0; i < vc[u].size(); i++) {
int v = vc[u][i];
if (v == rt)continue;
dfs(v, u); Siz[u] += Siz[v];
}
} int main()
{
//ios::sync_with_stdio(0);
//memset(head, -1, sizeof(head));
int T; rdint(T);
while (T--) {
int k; rdint(n); rdint(k);
for (int i = 0; i < maxn; i++)vc[i].clear();
for (int i = 1; i < n; i++) {
int u, v; rdint(u); rdint(v);
vc[u].push_back(v); vc[v].push_back(u);
}
dfs(1, 0);
int ans = 0;
for (int i = 1; i <= n; i++) {
if (Siz[i] >= k && (n - Siz[i]) >= k)ans++;
}
cout << ans << endl;
}
return 0;
}
Infinite Fraction Path
The
kingdom has N cities numbered from 0 to N - 1 and you are given an array
D[0 ... N - 1] of decimal digits (0 ≤ D[i] ≤ 9, D[i] is an integer).
The destination of the only one-way road start from the i-th city is the
city labelled (i2 + 1)%N.
A path beginning from the i-th city would pass through the cities u1,u2,u3,
and so on consecutively. The path constructs a real number A[i], called
the relevant fraction such that the integer part of it is equal to zero
and its fractional part is an infinite decimal fraction with digits
D[i], D[u1], D[u2], and so on.
The best infinite fraction path is the one with the largest relevant fraction
input contains multiple test cases and the first line provides an
integer up to 100 indicating to the total numberof test cases.
For
each test case, the first line contains the integer N (1 ≤ N ≤ 150000).
The second line contains an array ofdigits D, given without spaces.
The summation of N is smaller than 2000000.
each test case, you should output the label of the case first. Then you
are to output exactly N characters which are the first N digits of the
fractional part of the largest relevant fraction.
3
149
5
12345
7
3214567
9
261025520
Case #2: 53123
Case #3: 7166666
Case #4: 615015015
题意:
一个n个元素的字符串,从 i 位置出发的下一个位置为 (i*i-1)%n;
求最大的路径;
我们 bfs处理;
如果当前达到n个节点,那么弹出队列;
如果从不同位置出发到达了相同的位置,那么也continue,因为后续的过程还是一样;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream> //#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++) inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}
/*
int n, m;
int st, ed;
struct node {
int u, v, nxt, w;
}edge[maxn<<1]; int head[maxn], cnt; void addedge(int u, int v, int w) {
edge[cnt].u = u; edge[cnt].v = v; edge[cnt].w = w;
edge[cnt].nxt = head[u]; head[u] = cnt++;
} int rk[maxn]; int bfs() {
queue<int>q;
ms(rk);
rk[st] = 1; q.push(st);
while (!q.empty()) {
int tmp = q.front(); q.pop();
for (int i = head[tmp]; i != -1; i = edge[i].nxt) {
int to = edge[i].v;
if (rk[to] || edge[i].w <= 0)continue;
rk[to] = rk[tmp] + 1; q.push(to);
}
}
return rk[ed];
}
int dfs(int u, int flow) {
if (u == ed)return flow;
int add = 0;
for (int i = head[u]; i != -1 && add < flow; i = edge[i].nxt) {
int v = edge[i].v;
if (rk[v] != rk[u] + 1 || !edge[i].w)continue;
int tmpadd = dfs(v, min(edge[i].w, flow - add));
if (!tmpadd) { rk[v] = -1; continue; }
edge[i].w -= tmpadd; edge[i ^ 1].w += tmpadd; add += tmpadd;
}
return add;
}
ll ans;
void dinic() {
while (bfs())ans += dfs(st, inf);
}
*/ struct node {
ll stp, pos;
node(){}
node(ll stp,ll pos):stp(stp),pos(pos){}
}Nd;
queue<node>q;
int vis[maxn];
int ans[maxn], tmp[maxn];
string s;
int n; void bfs() {
while (!q.empty()) {
node tt = q.front(); q.pop();
if (tt.stp == n)continue;
// 已经有n个点,继续
if (tmp[tt.pos] == ans[tt.stp]) {
if (vis[tt.pos]==tt.stp)continue;
// 回到相同的地方
vis[tt.pos] = tt.stp;
tt.pos = (tt.pos*tt.pos + 1) % n;
tt.stp++;// 下一个状态
if (tmp[tt.pos] >= ans[tt.stp]) {
ans[tt.stp] = tmp[tt.pos]; q.push(tt);
}
}
}
} int main()
{
//ios::sync_with_stdio(0);
//memset(head, -1, sizeof(head));
int T; rdint(T);
for (int j = 1; j <= T; j++) {
while (!q.empty())q.pop();
rdint(n); cin >> s;
int maxx = -inf;
for (int i = 0; i < n; i++) {
tmp[i] = s[i] - '0';
maxx = max(maxx, tmp[i]);
}
for (int i = 0; i < n; i++) {
if (tmp[i] == maxx) {
q.push(node(1, i));
}
}
memset(vis, -1, sizeof(vis)); memset(ans, -1, sizeof(ans));
ans[1] = maxx;
bfs();
cout << "Case #" << j << ": ";
for (int i = 1; i <= n; i++)cout << ans[i];
cout << endl;
}
return 0;
}
Wandering Robots
an attempt to colonize Mars, some scientists were tasked with cleaning
the planet. A cleaning robot, Marsba,was build with a huge restricted
area in the Mars as a massive N × N square grid with K (K ≤ 1000)
impassable barriers. This area are numbered from (0, 0) to (N - 1, N -
1) sequentially from left to right, row by row, where N ≤ 10000. The
starting point of Marsba is situated on the top left corner lattice (0,
0). Marsba had instructions to program him with equal probability of
remaining in the same lattice or travelling to an adjacent one. (Two
lattices are said to be adjacent if they share a common edge.) This
meant an equal probability being split equally between remaining in the
lattice and the number of available routes. Specifically, for the
lattice Marsba located in which has d adjacent lattices without
impassable barriers, the probability for Marsba of remaining in the
lattice or travelling to any adjacent lattice is \frac{1}{d+1} .
Then, those scientists completely forgot about it.
Many millennia ago, a young man realizes the importance of the cleaning robot, Marsba, at the end of the forgotten.
For further research, he asks you to calculate the probability of Marsba’s location (x, y) satisfying x + y ≥ N - 1.
Let
the probability be an irreducible fraction of the form p/q, you should
output p and q respectively, with a fraction slash as the separator.
For
each case, the first line contains two positive integers N and K. Each
of the next K lines contains the coordinate of a barrier.
Note that
the starting point (0, 0) has no barrier and all test cases guarantee
the connectivity of all lattices free of barriers.
3 0
3 1
1 1
3 2
1 1
2 2
3 3
1 1
1 2
2 2
5 4
1 1
1 2
2 3
3 2
Case #2: 5/8
Case #3: 10/19
Case #4: 7/16
Case #5: 43/71
然后,那些科学家完全忘了它。
几千年前,一位年轻人意识到清洁机器人Marsba在被遗忘的最后阶段的重要性。
为了进一步研究,他要求你计算Marsba位置(x,y)满足x +y≥N - 1的概率。
设概率是p / q形式的不可约分数,你应该分别输出p和q,用分数斜杠作为分隔符。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream> //#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++) inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}
/*
int n, m;
int st, ed;
struct node {
int u, v, nxt, w;
}edge[maxn<<1]; int head[maxn], cnt; void addedge(int u, int v, int w) {
edge[cnt].u = u; edge[cnt].v = v; edge[cnt].w = w;
edge[cnt].nxt = head[u]; head[u] = cnt++;
} int rk[maxn]; int bfs() {
queue<int>q;
ms(rk);
rk[st] = 1; q.push(st);
while (!q.empty()) {
int tmp = q.front(); q.pop();
for (int i = head[tmp]; i != -1; i = edge[i].nxt) {
int to = edge[i].v;
if (rk[to] || edge[i].w <= 0)continue;
rk[to] = rk[tmp] + 1; q.push(to);
}
}
return rk[ed];
}
int dfs(int u, int flow) {
if (u == ed)return flow;
int add = 0;
for (int i = head[u]; i != -1 && add < flow; i = edge[i].nxt) {
int v = edge[i].v;
if (rk[v] != rk[u] + 1 || !edge[i].w)continue;
int tmpadd = dfs(v, min(edge[i].w, flow - add));
if (!tmpadd) { rk[v] = -1; continue; }
edge[i].w -= tmpadd; edge[i ^ 1].w += tmpadd; add += tmpadd;
}
return add;
}
ll ans;
void dinic() {
while (bfs())ans += dfs(st, inf);
}
*/ int dx[] = { 0,-1,1,0 };
int dy[] = { 1,0,0,-1 }; int T;
int n, k;
map<pii, int>Map; int Number(int x, int y) {
if ((x == 0 && y == 0) || (x == n - 1 && y == 0) || (x == n - 1 && y == n - 1) || (x == 0 && y == n - 1))return 3;
if ((x == 0) || (y == 0) || (x == n - 1) || (y == n - 1))return 4;
return 5;
} int suit(int x, int y) {
return (x + y) >= n - 1;
} int OK(int x, int y) {
return x >= 0 && x < n&&y >= 0 && y < n;
} int main()
{
//ios::sync_with_stdio(0);
//memset(head, -1, sizeof(head));
rdint(T); int tnt = 0;
while (T--) {
tnt++; rdint(n); rdint(k);
ll sum = 4 * 3 + 4 * (n - 2) * 4 + (n - 2)*(n - 2) * 5;
ll num3 = 3, num4 = (n - 2) * 2;
ll num5 = (n + 1)*n / 2 - num3 - num4;
ll curAns = num5 * 5 + num3 * 3 + num4 * 4;
Map.clear();
for (int i = 1; i <= k; i++) {
int x, y; rdint(x); rdint(y);
Map[make_pair(x, y)] = Number(x, y);
for (int j = 0; j < 4; j++) {
int nx = x + dx[j], ny = y + dy[j];
if (OK(nx, ny)) {
Map[make_pair(nx, ny)]++;
Map[make_pair(nx, ny)] = min(Map[make_pair(nx, ny)], Number(nx, ny));
}
}
}
int cnt = 0;
map<pii, int>::iterator it;
for (auto cnt : Map) {
int tmpx = cnt.first.first, tmpy = cnt.first.second;
int tmpz = cnt.second;
if (suit(tmpx, tmpy))curAns -= tmpz;
sum -= tmpz;
}
ll GCD = gcd(sum, curAns);
sum /= GCD; curAns /= GCD;
cout << "Case #" << tnt << ": ";
cout << curAns << "/" << sum << endl;
}
return 0;
}
2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)的更多相关文章
- HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/O ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛
HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- hdu 5510 Bazinga (kmp+dfs剪枝) 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
废话: 这道题很是花了我一番功夫.首先,我不会kmp算法,还专门学了一下这个算法.其次,即使会用kmp,但是如果暴力枚举的话,还是毫无疑问会爆掉.因此在dfs的基础上加上两次剪枝解决了这道题. 题意: ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛
C.Recursive sequence 求ans(x),ans(1)=a,ans(2)=b,ans(n)=ans(n-2)*2+ans(n-1)+n^4 如果直接就去解...很难,毕竟不是那种可以直 ...
- 2015ACM/ICPC亚洲区沈阳站重现赛-HDU5512-Pagodas-gcd
n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, l ...
- 2015ACM/ICPC亚洲区沈阳站-重现赛 M - Meeting (特殊建边,最短路)
题意:有\(n\)个点,\(m\)个集合,集合\(E_i\)中的点都与集合中的其它点有一条边权为\(t_i\)的边,现在问第\(1\)个点和第\(n\)个点到某个点的路径最短,输出最短路径和目标点,如 ...
- 2015ACM/ICPC亚洲区沈阳站-重现赛 B - Bazinga (KMP)
题意:给你\(n\)个字符串,\(s_1,s_2,...,s_n\),对于\(i(1\le i\le n)\),找到最大的\(i\),并且满足\(s_j(1\le j<i)\)不是\(s_i\) ...
随机推荐
- Drools学习笔记4—Consequence/RHS
Right Hand Side,当LHS所有条件满足才会执行 可以使用LHS部分定义的绑定变量.全局变量.或者直接编写JAVA代码. 提供宏函数操作working memory fact对象,如ins ...
- Java中弱引用、软引用、虚引用及强引用的区别
Java中弱引用VS软引用 Java中有如下四种类型的引用: 强引用(Strong Reference) 弱引用(WeakReference) 软引用(SoftReference) 虚引用(Phant ...
- 12-19Windows窗体应用程序之记事本(2)
之前记事本的功能实现了“文件”和“编辑”中的功能操作,现在再继续下面的功能介绍: 3) <1>字体设置 [查看代码] [效果图] <2>字体颜色的设置 [查看代码] [效果图] ...
- leetcode479
public class Solution { public int LargestPalindrome(int n) { ) ; , n) - ; ; v > max / ; v--) { S ...
- 【MySQL】20个经典面试题(转)
原文链接:http://bbs.51cto.com/thread-1470880-1.html Part2:经典题目 1.MySQL的复制原理以及流程 基本原理流程,3个线程以及之间的关联: 2.my ...
- TCP/IP 笔记 1.3 IP:网际协议
---恢复内容开始--- I P是T C P / I P协议族中最为核心的协议.所有的 T C P.U D P.I C M P及I G M P数据都以I P数据报格式传输. 不可靠( u n r e ...
- FTP 命令 上传下载
ftp ftp [-v] [-n] [-i] [-d] [-g] [-s:filename] [-a] [-w:windowsize] [computer] 参数-v 禁止显示远程服务器响应.-n ...
- IE双边距bug
标准参考 根据 W3C CSS2.1 规范中的描述,对于非替换的浮动元素,若 'margin-left' 或 'margin-right' 特性的计算值为 'auto',则它们的实际使用值为 '0'. ...
- Using JConsole
Using JConsole 转自 https://docs.oracle.com/javase/8/docs/technotes/guides/management/jconsole.html Th ...
- solr增量数据配置说明
转帖地址:http://www.blogjava.net/conans/articles/379546.html 以下资料整理自网络,觉的有必要合并在一起,这样方便查看.主要分为两部分,第一部分是对& ...