ACM-ICPC 2017 Asia Shenyang Solution
A: BBP Formula
https://www.cnblogs.com/LzyRapx/p/7802790.html
#include <bits/stdc++.h>
using namespace std; #define ll long long inline ll qpow(ll x, ll n, ll mod)
{
ll base = x;
ll ans = ;
while (n)
{
if (n & ) ans = (ans * base) % mod;
base = base * base % mod;
n >>= ;
}
return ans;
} inline double BBP(int n, ll k, ll b)
{
double res = 0.0;
for (int i = ; i <= n; ++i)
res += qpow(, n - i, ( * i + b)) * 1.0 / ( * i + b);
for (int i = n + ; i <= (n + ); ++i)
res += powf(, n - i) * 1.0 / ( * i + b);
return k * res;
} inline char print(double tmp)
{
int x = int(tmp);
if (x >= && x <= )
return x + '';
return x - + 'A';
} int t, n; inline void Run()
{
scanf("%d", &t);
for (int kase = ; kase <= t; ++kase)
{
scanf("%d", &n); --n;
double ans = BBP(n, , ) - BBP(n, , ) - BBP(n, , ) - BBP(n, , );
ans = ans - (int)ans;
if (ans < ) ans += 1.0;
ans *= 16.0;
printf("Case #%d: %d %c\n", kase, n + , print(ans));
}
} int main()
{
#ifdef LOCAL
freopen("Test.in", "r", stdin);
#endif Run(); return ;
}
B: Bridge
留坑。
C: Empty Convex Polygons
留坑。
D: Defense of the Ancients
留坑。
E: Five-roune Show Hand
留坑。
F:Heron and His Triangle
题意:给出一个n,找出一个最小的t满足 t >= n 并且 t-1 t t + 1 三条边组成的三角形的面积的整数
思路:根据海伦公式,然后打表,找出前几项是
4
14
52
194
724
然后发现 F(n) = 4F(n - 1) - F(n - 2)
可以发现,这个数增长的很快,60多项就会超过10^30了 用JAVA打个表,然后暴力找或者二分找都可以
import java.math.BigInteger;
import java.util.Scanner; public class Main
{ public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
BigInteger ans[] = new BigInteger[200 + 10];
ans[0] = BigInteger.valueOf(4);
ans[1] = BigInteger.valueOf(14);
for(int i = 2; i <= 200; ++i)
{
ans[i] = ans[i - 1].multiply(BigInteger.valueOf(4));
ans[i] = ans[i].subtract(ans[i - 2]);
}
int T = in.nextInt();
for(int cas = 1; cas <= T; ++cas)
{
BigInteger n = in.nextBigInteger();
for(int i = 0; i <= 200; ++i)
{
if(ans[i].compareTo(n) >= 0)
{
System.out.println(ans[i]);
break;
}
}
}
}
}
G: Infinite Fraction Path
题意:给出长度为n的字符串,对于第i位的数,它和第(i^2 + 1) % n位的数有一条有向边,从一个数出发,走n - 1 步,得到一个长度为n的字符串,输出字典树最大的那个
思路:考虑搜索
贪心的想法肯定是第一步是字母序最大的那个字母开始
两条剪枝:
第一条:每次扩展一步,如果有一个点扩展出来到这一位的字母小于其它点过来的 剪掉
第二条:每次扩展一步,如果下标被相同步数到达这里的访问过,剪掉
#include<bits/stdc++.h> using namespace std; #define N 200010
typedef long long ll; int n;
char str[N];
char ans[N];
int used[N]; struct node{
ll idx;
int step;
inline node(){}
inline node(ll idx, int step) :idx(idx), step(step){}
}; queue<node>q; inline void Init()
{
while(!q.empty()) q.pop();
memset(ans, , sizeof ans);
memset(used, , sizeof used);
} inline void BFS()
{
node st, now;
while(!q.empty())
{
st = q.front();
q.pop();
if(st.step > n - ) continue;
if(str[st.idx] < ans[st.step]) continue;
if(str[st.idx] > ans[st.step])
ans[st.step] = str[st.idx];
now.idx = (st.idx * st.idx + ) % n;
now.step = st.step + ;
if(str[now.idx] < ans[now.step]) continue;
if(used[now.idx] == now.step) continue;
used[now.idx] = now.step;
q.push(now);
if(str[now.idx] > ans[now.step])
ans[now.step] = str[now.idx];
}
} int main()
{
int t;
scanf("%d",&t);
for(int cas = ; cas <= t; ++cas)
{
Init();
scanf("%d", &n);
scanf("%s", str);
char Max = ;
for(int i = ; i < n; ++i)
{
Max = max(Max, str[i]);
}
for(int i = ; i < n; ++i)
{
if(str[i] == Max)
q.push(node(i, ));
}
BFS();
printf("Case #%d: ", cas);
for(int i = ; i < n; ++i)
{
printf("%c",ans[i]);
}
printf("\n");
}
return ;
}
H:Legends of the Three Kingdoms
留坑。
I:Little Boses
ull的范围是2 ^ 64 - 1
#include <bits/stdc++.h> using namespace std;
#define ull unsigned long long int t;
ull a[]; inline bool check()
{
ull D = 1ull << ;
for (int i = ; i < ; ++i)
if (a[i] != D)
return false;
return true;
} int main()
{
scanf("%d", &t);
while (t--)
{
for (int i = ; i < ; ++i) scanf("%llu", a + i);
if (check())
{
puts("");
continue;
}
else
{
ull sum = ;
for (int i = ; i < ; ++i) sum += a[i];
printf("%llu\n", sum);
}
}
return ;
}
J:New Self-describing Sequence
留坑。
K:Rabbits
题意:有n只小兔子,如果两个小兔子中间有间隙,那么在这两个小兔子之外的兔子可以跳到某一个间隙中,求最多能跳多少步
思路:显然 答案是 最左边那个小兔子到最右边的左边的小兔子的间隙数和最右边小兔子到最左边的右边的小兔子的间隙取max
#include <bits/stdc++.h> using namespace std; #define N 510 int t;
int n;
int arr[N]; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = ; i <= n; ++i)
scanf("%d", arr + i);
int ans = ;
ans = arr[n - ] - arr[] + - n + ;
ans = max(ans, arr[n] - arr[] - n + );
printf("%d\n", ans);
}
return ;
}
L:Tree
题意:给出一棵树,k种颜色,每种颜色的边集是选取最少的边使得这些边覆盖所有这种颜色的点,求k中颜色的边集并
思路:显然,如果一条边存在于所有颜色的边集当中,那么它连接的两边的端点个数一定>= k
#include <bits/stdc++.h> using namespace std; #define N 200010 struct node
{
int to, nx;
inline node() {}
inline node(int to, int nx) : to(to), nx(nx) {}
}edge[N << ]; int head[N], pos;
int used[N];
int sum[N]; inline void Init()
{
memset(head, -, sizeof head);
memset(used, , sizeof used);
memset(sum, , sizeof sum);
pos = ;
} inline void addedge(int u, int v)
{
edge[++pos] = node(v, head[u]); head[u] = pos;
edge[++pos] = node(u, head[v]); head[v] = pos;
} int ans;
int t, n, k; inline void DFS(int u)
{
used[u] = ;
sum[u] = ;
for (int it = head[u]; ~it; it = edge[it].nx)
{
int v = edge[it].to;
if (used[v] == ) continue;
DFS(v);
sum[u] += sum[v];
}
if (sum[u] >= k && (n - sum[u] >= k)) ++ans;
} int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &n, &k);
Init();
for (int i = , u, v; i < n; ++i)
{
scanf("%d%d", &u, &v);
addedge(u, v);
}
ans = ;
DFS();
printf("%d\n", ans); }
return ;
}
M:Wandering Robots
题意:给出n * n 的矩形,有k个障碍物,机器人刚开始在(0, 0) 点,它会等概率的选择停留在原地,或者走向相邻的可走的格子(即没有障碍物的),时间过去了很久,求机器人在(x, y) (x + y >= n - 1) 的点的概率
思路:LTS大神推出答案就是 (满足条件的点的可能性) / (所有点的可能性)
先公式求出所有点的可能性
然后枚举障碍物,减去多加的可能性
首先障碍物本身要减去自身的可能性,如果它的相邻点不是障碍物,还要减去一
#include<bits/stdc++.h> using namespace std; typedef long long ll;
typedef pair <int, int> pii; inline ll gcd(ll a, ll b)
{
while(b ^= a ^= b ^= a %= b);
return a;
} ll n, k; map <pii, int> mp; int Move[][] =
{
, ,
,-,
, ,
-, ,
}; inline bool ok(int x, int y)
{
if (x < || x >= n || y < || y >= n) return false;
return true;
} int main()
{
int t;
scanf("%d",&t);
for(int cas = ; cas <= t; ++cas)
{
scanf("%lld %lld", &n, &k);
mp.clear();
for (int i = , x, y; i <= k; ++i)
{
scanf("%d%d", &x, &y);
mp[pii(x, y)] = ;
}
printf("Case #%d: ", cas);
if (n == )
{
if (k == )
puts("1/1");
else
puts("0/0");
}
else
{
ll fenmu = (n - ) * (n - ) * + * (n - ) + ;
ll fenzi = (n - ) * + * (n - ) * (n - ) / + ;
for (map<pii, int>::iterator it = mp.begin(); it != mp.end(); ++it)
{
int x = it->first.first, y = it->first.second;
int tmp = ;
if (x == || x == n - )
tmp--;
if (y == || y == n - )
tmp--;
fenmu -= tmp;
if (x + y >= n - )
fenzi -= tmp;
for (int i = ; i < ; ++i)
{
int dx = x + Move[i][];
int dy = y + Move[i][];
if (!ok(dx, dy)) continue;
if (mp.count(pii(dx, dy)) == ) continue;
--fenmu;
if (dx + dy >= n - )
--fenzi;
}
}
ll G = gcd(fenzi, fenmu);
fenzi /= G, fenmu /= G;
printf("%lld/%lld\n", fenzi, fenmu);
}
}
return ;
}
ACM-ICPC 2017 Asia Shenyang Solution的更多相关文章
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...
- 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2017 ACM ICPC Asia Regional - Daejeon
2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...
- 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...
- Problem 1002-2017 ACM/ICPC Asia Regional Shenyang Online
网络赛:2017 ACM/ICPC Asia Regional Shenyang Online 题目来源:cable cable cable Problem Description: Connecti ...
- 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元
hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
随机推荐
- android素材资源
这里先给大家 推荐两个 找图标的 搜索引擎 http://findicons.com/ 这个我也在用 大家也可以试试 找个图标还是很easy的. http://www.iconfinder. ...
- Python 流程控制:for
for 循环用于对一个序列进行遍历,用法如下: In [4]: for i in 'abcd': ...: print(i) ...: a b c d In [13]: for i in range( ...
- Java环境变量中classpath是必须配置吗
设置环境变量在java 中需要设置三个环境变量(1.5之后不用再设置classpath了,但个人强烈建议继续设置以保证向下兼用问题)JDK安装完成之后我们来设置环境变量:右击“我的电脑”,选择“属性” ...
- IP地址转、整数互相转换
知识点:一个二进制数,按位左移n位,就是把该数的值乘以2的n次方 二进制除二即右移一位 1.IP地址转换为整数 原理:IP地址每段可以看成是8位无符号整数即0-255 ...
- MUI 页面跳转(传值+接收)
官方:做web app,一个无法避开的问题就是转场动画:web是基于链接构建的,从一个页面点击链接跳转到另一个页面, 如果通过有刷新的打开方式,用户要面对一个空白的页面等待: 如果通过无刷新的方式,用 ...
- OpenGL ES2学习笔记(6)-- Line Strip和Line Loop
Line Strip 上一篇文章画了两条线段,但是用了4个点.如果几条线段首尾相接的话,可以让OpenGL把他们当成Line Strip来画,这样就可以用n+1个点来画n条线段. 代码 import ...
- android基础---->DiskLruCache的使用及原理
DiskLruCache是谷歌推荐的用来实现硬盘缓存的类,今天我们开始对于DiskLruCache的学习.DiskLruCache的测试代码:DiskLruCache的测试代码下载.关于FidkLru ...
- 【CSS系列】块级元素和行内元素
块级元素: 块级元素生成一个元素框,默认会填充其父元素的内容区,旁边不能有其他元素,换句话说,它在元素框之前和之后生成了“分隔符”. 列表项是块级额元素的一个特例,除了表现方式与其他块元素一致,列表项 ...
- vue报错一
8080端口被占用 解决方案: 打开cmd输入:netstat -ano查看所有端口信息,如图,找到端口 8080,以及对应的 PID: 输入:tskill PID 即可杀死进程,ex:: tskil ...
- C# MVC跳转
MVC方式: 显示提示框,并返回上一页 return Content("<script>alert('暂时没有实践作业!');history.go(-1);</script ...