A Eddy Walker

题意

你有n个点(0~n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步,

一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来。

问你最后停留在m这个位子的概率是多少。

注意输出的答案是前缀积。

思路

有意思的概率题。

读懂题意后发现这道题不难,模拟下可以发现在最后落在(1~n-1)的位子是等概率的,落在0这个位子是不可能的(除非n==1)。

  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <algorithm>
  5. using namespace std;
  6. #define pb push_back
  7. #define fi first
  8. #define se second
  9. #define debug(x) cerr<<#x << " := " << x << endl;
  10. #define bug cerr<<"-----------------------"<<endl;
  11. #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
  12.  
  13. typedef long long ll;
  14. typedef long double ld;
  15. typedef pair<int, int> pii;
  16. typedef pair<ll, ll> pll;
  17.  
  18. template<class T> void _R(T &x) { cin >> x; }
  19. void _R(int &x) { scanf("%d", &x); }
  20. void _R(ll &x) { scanf("%lld", &x); }
  21. void _R(double &x) { scanf("%lf", &x); }
  22. void _R(char &x) { scanf(" %c", &x); }
  23. void _R(char *x) { scanf("%s", x); }
  24. void R() {}
  25. template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
  26.  
  27. template<typename T>
  28. inline T read(T&x){
  29. x=;int f=;char ch=getchar();
  30. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  31. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  32. return x=f?-x:x;
  33. }
  34.  
  35. const int inf = 0x3f3f3f3f;
  36.  
  37. const int mod = 1e9+;
  38.  
  39. /**********showtime************/
  40. ll ksm(ll a, ll b) {
  41. ll res = ;
  42. while(b > ) {
  43. if(b & ) res = res * a % mod;
  44. a = a * a % mod;
  45. b = b >> ;
  46. }
  47. return res;
  48. }
  49. int main(){
  50. int T; scanf("%d", &T);
  51. ll res = ;
  52. while(T--){
  53. ll n,m;
  54. scanf("%lld%lld", &n, &m);
  55. if(n == && m == ) res = res;
  56. else {
  57. if(m == ) res = res * ;
  58. else {
  59. res = res * ksm(n-, mod-) % mod;
  60. }
  61. }
  62. printf("%lld\n", res);
  63. }
  64.  
  65. return ;
  66. }

B Eddy Walker 2

BM

D Kth Minimum Clique

题意:

 在一个无向图中,找出一个权值为第K小的最小团,最小团的定义为选出的公共节点间有边直接联通。

思路:

 感觉实现起来不太难。既然要选择第K小的,我们可以从小到大做。每次通过最小的一个最小团扩展,可以利用bitset优化判断扩展的可行性。

 即利用优先队列,从其中取出的第k个就是答案。

 有点像dji找最短路

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define fi first
  5. #define se second
  6. #define debug(x) cerr<<#x << " := " << x << endl;
  7. #define bug cerr<<"-----------------------"<<endl;
  8. #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
  9.  
  10. typedef long long ll;
  11. typedef long double ld;
  12. typedef pair<int, int> pii;
  13. typedef pair<ll, ll> pll;
  14.  
  15. template<class T> void _R(T &x) { cin >> x; }
  16. void _R(int &x) { scanf("%d", &x); }
  17. void _R(ll &x) { scanf("%lld", &x); }
  18. void _R(double &x) { scanf("%lf", &x); }
  19. void _R(char &x) { scanf(" %c", &x); }
  20. void _R(char *x) { scanf("%s", x); }
  21. void R() {}
  22. template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
  23.  
  24. template<typename T>
  25. inline T read(T&x){
  26. x=;int f=;char ch=getchar();
  27. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  28. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  29. return x=f?-x:x;
  30. }
  31.  
  32. const int inf = 0x3f3f3f3f;
  33.  
  34. const int mod = 1e9+;
  35.  
  36. /**********showtime************/
  37.  
  38. const int maxn = ;
  39. char str[maxn];
  40. struct node{
  41. ll val;
  42. bitset<>bs;
  43. bool operator<(const node & o) const{
  44. return val > o.val;
  45. }
  46. }a[maxn];
  47. int main(){
  48. int n,k;
  49. scanf("%d%d", &n, &k);
  50. for(int i=; i<=n; i++) {
  51. scanf("%lld", &a[i].val);
  52. }
  53. for(int i=; i<=n; i++) {
  54. scanf("%s", str+);
  55. for(int j=; j<=n; j++) {
  56. if(str[j] == '')a[i].bs.set(j);
  57. }
  58. }
  59.  
  60. priority_queue<node>que;
  61. node s;
  62. s.val = ;
  63. s.bs.reset();
  64. que.push(s);
  65. int flag = ;ll res;
  66. while(!que.empty()) {
  67. node u = que.top();
  68. que.pop();
  69. k -- ;
  70. if(k == ) {
  71. flag = ;
  72. res = u.val;
  73. break;
  74. }
  75. int mx = ;
  76. for(int i=; i<=n; i++) {
  77. if(u.bs[i] == ) mx = i + ;
  78. }
  79.  
  80. for(int i=mx; i<=n; i++) {
  81. if((u.bs & a[i].bs) == u.bs) {
  82. u.bs.set(i); u.val += a[i].val;
  83. que.push(u);
  84. u.bs.reset(i); u.val -= a[i].val;
  85. }
  86. }
  87. }
  88. if(flag) printf("%lld\n", res);
  89. else puts("-1");
  90. return ;
  91. }

E MAZE

线段树,dp

F Partition problem

比赛时过的,双向搜索降低复杂度(队友搞的,我还没搞)

I Inside A Rectangle

dp

H Second Large Rectangle

比赛时过的。DP出面积,找出次大的

(队友搞的,我还没搞)

J Subarray

题意:

有一个长度为1E9,值为{-1,1}的数组,保证只有n(<1e6)个区间等于1,且1的个数小于1e7。

求有多少对区间的区间和大于0。

思路:

首先把被答案区间所包含的点都找出来。最多只有3e7个点。怎么找?

从小到达遍历数组,把每个区间向右扩展的长度找出来,

从大到小遍历数组,把每个区间向左扩展的长度找出来。

然后计算每个点的前缀和。在一个点前面且前缀和小于当前点的前缀和的一个点对应ans++。

由于前缀和的变化大小为1,所以不用树状数组即可完成。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define fi first
  5. #define se second
  6. #define debug(x) cerr<<#x << " := " << x << endl;
  7. #define bug cerr<<"-----------------------"<<endl;
  8. #define FOR(a, b, c) for(int a = b; a <= c; ++ a)
  9.  
  10. typedef long long ll;
  11. typedef long double ld;
  12. typedef pair<int, int> pii;
  13. typedef pair<ll, ll> pll;
  14.  
  15. template<class T> void _R(T &x) { cin >> x; }
  16. void _R(int &x) { scanf("%d", &x); }
  17. void _R(ll &x) { scanf("%lld", &x); }
  18. void _R(double &x) { scanf("%lf", &x); }
  19. void _R(char &x) { scanf(" %c", &x); }
  20. void _R(char *x) { scanf("%s", x); }
  21. void R() {}
  22. template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
  23.  
  24. template<typename T>
  25. inline T read(T&x){
  26. x=;int f=;char ch=getchar();
  27. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  28. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  29. return x=f?-x:x;
  30. }
  31.  
  32. const int inf = 0x3f3f3f3f;
  33. const ll inff = 0x3f3f3f3f3f3f3f3f;
  34. const int mod = 1e9+;
  35.  
  36. /**********showtime************/
  37. const int maxm = 2e7+;
  38. const int maxn = 1e6+;
  39. int le[maxn],ri[maxn];
  40. int lto[maxn],rto[maxn];
  41. ll f[maxm];
  42. int g(int x) {
  43. return x + ;
  44. }
  45. int main(){
  46. int n;
  47. scanf("%d", &n);
  48.  
  49. for(int i=; i<=n; i++) scanf("%d%d", &le[i], &ri[i]);
  50.  
  51. int sum = ;
  52. /// 向右扩展
  53. le[n+] = ;
  54. for(int i=; i<=n; i++) {
  55. sum += ri[i] - le[i] + ;
  56. rto[i] = min(sum, le[i+] - ri[i] - );
  57. sum -= le[i+] - ri[i] - ;
  58. if(sum < ) sum = ;
  59. }
  60. /// 向左扩展
  61. sum = ;
  62. ri[] = -;
  63.  
  64. for(int i=n; i>=; i--) {
  65. sum += ri[i] - le[i] + ;
  66. lto[i] = min(sum , le[i] - ri[i-] -);
  67. sum -= le[i] - ri[i-] - ;
  68. if(sum < ) sum = ;
  69. }
  70.  
  71. ///计算每个点的前缀和。lowsum保存前缀和比当前点小的个数
  72. ll ans = , lowsum = ;
  73. int s = , pos = ;
  74. f[g()] = ;
  75. for(int i=; i<=n; i++) {
  76.  
  77. for(int j=max(pos, le[i] - lto[i]); j<=ri[i] + rto[i]; j++) {
  78.  
  79. if(j>=le[i] && j <= ri[i]) {
  80. lowsum += f[g(s)];
  81. s++;
  82. f[g(s)]++;
  83. ans += lowsum;
  84. }
  85. else {
  86. s--;
  87. lowsum -= f[g(s)];
  88. f[g(s)]++;
  89. ans += lowsum;
  90. }
  91. // cout<<j<<" "<<lowsum<<endl;
  92. pos = j+;
  93. }
  94. }
  95. // cout<<endl;
  96. printf("%lld\n", ans);
  97. return ;
  98. }

2019nc#2的更多相关文章

  1. 2019nc#10

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Blackjack 点击查看 背包DP 32/109 补好了 B Coffee Chicken 点击查看 进入讨论 738/2992  通过 ...

  2. 2019nc#9

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A The power of Fibonacci 点击查看 进入讨论 69/227 未通过 B Quadratic equation 点击查看 ...

  3. 2019NC#8

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A All-one Matrices 点击查看 单调栈+前缀和 326/2017  通过 B Beauty Values 点击查看 进入讨论 8 ...

  4. 2019nc#7

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A String 点击查看 进入讨论 566/3539  通过 B Irreducible Polynomial 点击查看 规律 730/229 ...

  5. 2019nc#6

    https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...

  6. 2019nc#5

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A digits 2 点击查看 1017/2384  通过 B generator 1 点击查看 567/3692  通过 C generato ...

  7. 2019nc#4

    题号 标题 已通过代码 题解 通过率 团队的状态 A meeting 点击查看 树直径 604/2055   B xor 点击查看 线段树维护线性基交 81/861 未通过 C sequence 点击 ...

  8. 2019nc#3

    题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Graph Games 点击查看 进入讨论 18/292 未通过 B Crazy Binary String 点击查看 1107/3615 ...

  9. 2019NC#1

    LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...

随机推荐

  1. Shell基本语法---常见的条件判断

    语法 [ 判断表达式 ] 文件夹或路径是否存在 -e 目标是否存在(exist) -d 是否为路径(directory) -f 是否为文件(file) [ -e text.sh ] || touch ...

  2. 以太坊solidity智能合约-生成随机数

    Solidity随机数生成 在以太坊的只能合约中,没有提供像其他面向对象编程一样的生成随机数的工具类或方法.其实,所谓的随机数也是伪随机的,没有哪一种语言能够真正的生成随机数. 对于solidity来 ...

  3. Ubuntu 下jdk的安装

    因为我ubuntu下需要运行一个java程序,其实是想做一下tc,因为浏览器要运行java插件,那个客户端一直下载不了,我记得我装过的,这个问题后面说.然后我就打算重新安装,通过查找资料,终于解决了手 ...

  4. golang-http 请求---设置header与直接发

    背景 现在各种软件到处都是,写代码难免有时候需要http 调用其他的接口. 其实这个东西还挺常用,虽然很简单,但是写的时候 又忘,就像是提笔忘字,索性总结一下吧. 不需要设置header属性的http ...

  5. oracle的开窗函数

    原创 select * from (select province, commodity, sum(price), ROW_NUMBER() OVER(PARTITION BY province  o ...

  6. Django是如何防止注入攻击-XSS攻击-CSRF攻击

    注入攻击-XSS攻击-CSRF攻击介绍请访问:https://www.cnblogs.com/hwnzy/p/11219475.html Django防止注入攻击 Django提供一个抽象的模型层来组 ...

  7. MQ如何解决消息的顺序性

    一.消息的顺序性 1.延迟队列:设置一个全局变量index,根据实际情况一次按照index++的逻辑一次给消息队列设置延迟时间段,可以是0.5s,甚至1s; 弊端:如果A,B,C..消息队列消费时间不 ...

  8. NS3中一些难以理解的常数

    摘要:在NS3的学习中,PHY MAC中总有一些常数,需要理解才能修改.如帧间间隔等.那么,本文做个简单分析,帮助大家理解.针对802.11标准中MAC协议.   void WifiMac::Conf ...

  9. 如何编写一个WebPack的插件原理及实践

    _ 阅读目录 一:webpack插件的基本原理 二:理解 Compiler对象 和 Compilation 对象 三:插件中常用的API 四:编写插件实战 回到顶部 一:webpack插件的基本原理 ...

  10. hadoop学习(二)----HDFS简介及原理

    前面简单介绍了hadoop生态圈,大致了解hadoop是什么.能做什么.带着这些目的我们深入的去学习他.今天一起看一下hadoop的基石--文件存储.因为hadoop是运行与集群之上,处于分布式环境之 ...