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. linux--解决oracle sqlplus 中上下左右backspace不能用

    1.  解决不能backspace 方法1: stty erase ^h 在oracle用户下:在用户环境配置文件.bash_profile中加入如下语句 stty erase ^h 方法2:在sec ...

  2. C++的virtual详解

    类的多态特性是支持面向对象的语言最主要的特性,有过非面向对象语言开发经历的人,通常对这一章节的内容会觉得不习惯,因为很多人错误的认为,支持类的封装的语言就是支持面向对象的,其实不然,Visual BA ...

  3. poj_3274 哈希

    哈希 Hash 哈希是一种将复杂数据转换为线性数据从而可以进行随机访问的查找算法. 哈希经常用于对复杂数据(如结构体.对象等)的查找,在使用的时候,需要定义一个Hash函数,将需要查找的复杂对象转化为 ...

  4. 设计模式之模板方法模式(Java实现)

    "那个,上次由于我老婆要给我做饭,所以就没有说完就走掉了...这个那个".这次和以前一样,先来开场福利(工厂方法模式已被作者踹下场).由美女抽象工厂介绍一下适用场景~大家欢迎 抽象 ...

  5. Centos7 安装zabbix3.0 服务端 详细

    参考: https://www.cnblogs.com/37yan/p/6879218.html http://blog.csdn.net/hao134838/article/details/5712 ...

  6. SDOI 2016 Round1 Day2

    生成魔咒 /* 后缀数组+双向链表 参照:https://blog.csdn.net/clove_unique/article/details/53911757 */ #include<cstd ...

  7. Swift - 把汉字转换为拼音,并且截取首字母做索引用

    var transformContents = CFStringCreateMutableCopy(nil, 0, "咋啊的看到回复阿斯顿发货发哦iasdifas") CFStri ...

  8. 微信小程序 --- 页面跳转

    第一种:wx.navigateTo({}); 跳转: 注意:这种跳转回触发当前页面的 onHide 方法,将当前页面隐藏,然后显示跳转页面.所以可以返回,返回的时候触发 onShow方法进行显示: ( ...

  9. <bean> 中配置详解 </bean>

    <bean> ***</bean> 这叫做Spring的依赖注入也叫控制反转.bean的id也就是你说的bean的id,通过id找你想要调用的bean <bean id= ...

  10. 170505、MySQL的or/in/union与索引优化

    假设订单业务表结构为: order(oid, date, uid, status, money, time, …) 其中: oid,订单ID,主键 date,下单日期,有普通索引,管理后台经常按照da ...