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的更多相关文章

  1. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  2. 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 ...

  3. ACM ICPC 2017 Warmup Contest 1 D

    Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...

  4. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  5. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  6. 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\)个白箱,将这 ...

  7. Problem 1002-2017 ACM/ICPC Asia Regional Shenyang Online

    网络赛:2017 ACM/ICPC Asia Regional Shenyang Online 题目来源:cable cable cable Problem Description: Connecti ...

  8. 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  9. 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 ...

随机推荐

  1. Python Scrapy 自动爬虫注意细节(2)

    一.自动爬虫的创建,需要指定模版 如: scrapy genspider -t crawl stockinfo quote.eastmoney.com crawl : 爬虫模版 stockinfo : ...

  2. 实现Runnable接口和继承Thread类区别

    如果一个类继承Thread,则不适合资源共享.但是如果实现了Runable接口的话,则很容易的实现资源共享. 实现Runnable接口比继承Thread类所具有的优势: 1):适合多个相同的程序代码的 ...

  3. C++11-新增正则表达式

    #include <regex> #include <iostream> #include <string> #include <atlstr.h> s ...

  4. 【PHP】算法进阶,获取给定值的最优组合:虚拟币抵扣问题解决方案

    商城里边.虚拟币抵扣问题解决方案 虚拟币抵扣规则,按照以下规则执行: 1.如果一个订单包含多款商品,且均支持虚拟币抵扣时:   优先按照最大化使用虚拟币进行全额抵扣原则进行抵扣,若抵扣后用户虚拟币账号 ...

  5. cache buffers chains以及热块解决方案

    cache buffers chains以及热块解决方案 今天是2013-10-10,今天下午我调休了,中午饭过后从14点一直睡到16点,这种感觉真爽.  之前学习过关于buffer cache的ca ...

  6. Add a try-catch with Mono Cecil

    Adding exception handlers with Mono.Cecil is not difficult, it just requires you to know how excepti ...

  7. 百度地图API开发----手机地图做导航功能

    第一种方式:手机网页点击打开直接进百度地图APP <a href="baidumap://map/direction?mode=[transit:公交,driving:驾车]& ...

  8. mysql 使用如下三种方式应用where条件,从好到坏

    在索引中使用where条件过滤不匹配的记录,这是在存储引擎层完成的: ​使用索引覆盖扫描(explain语句中的Extra列中出现Using index)来返回记录.直接从索引中过滤掉不需要的记录并返 ...

  9. Oracle开发 之 主-外键约束FK及约束的修改

    试验环境: 1)数据库版本:oracle 11.2.0.4 2)建表脚本:以scott的dept及emp表为基础. 父表:dept -- Create table create table DEPT ...

  10. Popular Cows---poj2186(缩点,强联通)

    题目链接:http://poj.org/problem?id=2186 求有多少个点满足其他n-1个点都能到达这个点,是单向图: 所以我们可以把图进行缩点,之后求出度为0的那个点内包含的点的个数就是求 ...