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 ...
随机推荐
- NPOI抓取WPS表格保存的EXCEL文件
其实是可以抓取的,唯一不同就是Sheet的位置前进了一位. var sheet1 = (HSSFSheet)hssfworkbook.GetSheetAt(1); 来自为知笔记(Wiz ...
- XMPP HTTP
1.TCP连接 要想明白Socket连接,先要明白TCP连接.手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上 ...
- PyQt4文件对话框QFileDialog
文件对话框允许用户选择文件或文件夹,被选择的文件可进行读或写操作. #!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 im ...
- iOS-利用插件实时刷新模拟器(提高效率)
解决办法: 1.需要给Xcode安装一个Alcatraz插件 安装完成后:点击window 下面的 package manager 安装我们今天的主角 2. ‘Injection Plugin for ...
- qq邮箱发送,mail from address must be same as authorization user
由于邮箱发送的邮箱账号更换,所以重新测试.结果一直出错,要不就是请求超时,要不就是未授权. 用smtp 开始的时候,端口使用495,结果是请求超时. 后来改成25,结果是未授权. 再后来听人说,有一个 ...
- MySql学习—— 查询性能优化 深入理解MySql如何执行查询
本篇深入了解查询优化和服务器的内部机制,了解MySql如何执行特定查询,从中也可以知道如何更改查询执行计划,当我们深入理解MySql如何真正地执行查询,明白高效和低效的真正含义,在实际应用中就能扬长避 ...
- css选择器的性能
性能排序: 1.id选择器(#myid) 2.类选择器(.myclassname) 3.标签选择器(div,h1,p) 4.相邻选择器(h1+p) 5.子选择器(ul < li) 6.后代选择器 ...
- Ubuntu16.04安装Nessus和MSF
一.Nessus篇: 1.参考文献:https://www.cnblogs.com/shamojituan/p/6511208.html 2.下载地址:https://downloads.nessus ...
- gvim编辑器_vimrc文件
set nocompatiblesource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswin set dif ...
- Promise、async、await在Egret的简单应用
Egret Engnie 5.1.10 Egret Wing 4.1.5 一.Promise.async.await相关知识 Promise介绍 阮一峰 async函数 阮一峰 具体和详细的说明用法可 ...