A Eddy Walker

题意

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

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

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

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

思路

有意思的概率题。

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

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} const int inf = 0x3f3f3f3f; const int mod = 1e9+; /**********showtime************/
ll ksm(ll a, ll b) {
ll res = ;
while(b > ) {
if(b & ) res = res * a % mod;
a = a * a % mod;
b = b >> ;
}
return res;
}
int main(){
int T; scanf("%d", &T);
ll res = ;
while(T--){
ll n,m;
scanf("%lld%lld", &n, &m);
if(n == && m == ) res = res;
else {
if(m == ) res = res * ;
else {
res = res * ksm(n-, mod-) % mod;
}
}
printf("%lld\n", res);
} return ;
}

B Eddy Walker 2

BM

D Kth Minimum Clique

题意:

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

思路:

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

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

 有点像dji找最短路

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} const int inf = 0x3f3f3f3f; const int mod = 1e9+; /**********showtime************/ const int maxn = ;
char str[maxn];
struct node{
ll val;
bitset<>bs;
bool operator<(const node & o) const{
return val > o.val;
}
}a[maxn];
int main(){
int n,k;
scanf("%d%d", &n, &k);
for(int i=; i<=n; i++) {
scanf("%lld", &a[i].val);
}
for(int i=; i<=n; i++) {
scanf("%s", str+);
for(int j=; j<=n; j++) {
if(str[j] == '')a[i].bs.set(j);
}
} priority_queue<node>que;
node s;
s.val = ;
s.bs.reset();
que.push(s);
int flag = ;ll res;
while(!que.empty()) {
node u = que.top();
que.pop();
k -- ;
if(k == ) {
flag = ;
res = u.val;
break;
}
int mx = ;
for(int i=; i<=n; i++) {
if(u.bs[i] == ) mx = i + ;
} for(int i=mx; i<=n; i++) {
if((u.bs & a[i].bs) == u.bs) {
u.bs.set(i); u.val += a[i].val;
que.push(u);
u.bs.reset(i); u.val -= a[i].val;
}
}
}
if(flag) printf("%lld\n", res);
else puts("-1");
return ;
}

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,所以不用树状数组即可完成。

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; /**********showtime************/
const int maxm = 2e7+;
const int maxn = 1e6+;
int le[maxn],ri[maxn];
int lto[maxn],rto[maxn];
ll f[maxm];
int g(int x) {
return x + ;
}
int main(){
int n;
scanf("%d", &n); for(int i=; i<=n; i++) scanf("%d%d", &le[i], &ri[i]); int sum = ;
/// 向右扩展
le[n+] = ;
for(int i=; i<=n; i++) {
sum += ri[i] - le[i] + ;
rto[i] = min(sum, le[i+] - ri[i] - );
sum -= le[i+] - ri[i] - ;
if(sum < ) sum = ;
}
/// 向左扩展
sum = ;
ri[] = -; for(int i=n; i>=; i--) {
sum += ri[i] - le[i] + ;
lto[i] = min(sum , le[i] - ri[i-] -);
sum -= le[i] - ri[i-] - ;
if(sum < ) sum = ;
} ///计算每个点的前缀和。lowsum保存前缀和比当前点小的个数
ll ans = , lowsum = ;
int s = , pos = ;
f[g()] = ;
for(int i=; i<=n; i++) { for(int j=max(pos, le[i] - lto[i]); j<=ri[i] + rto[i]; j++) { if(j>=le[i] && j <= ri[i]) {
lowsum += f[g(s)];
s++;
f[g(s)]++;
ans += lowsum;
}
else {
s--;
lowsum -= f[g(s)];
f[g(s)]++;
ans += lowsum;
}
// cout<<j<<" "<<lowsum<<endl;
pos = j+;
}
}
// cout<<endl;
printf("%lld\n", ans);
return ;
}

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. Gridea+GitHub搭建个人博客

    某日闲余时间看到一篇介绍Gridea博客平台的文章,大概看了一下觉得此平台还不错,随即自己进入Gridea官网瞅了瞅.哇,这搭建过程也太简单了吧,比Hexo博客搭建要容易很多,而且还有后台管理客户端, ...

  2. 现代c++与模板元编程

    最近在重温<c++程序设计新思维>这本经典著作,感慨颇多.由于成书较早,书中很多元编程的例子使用c++98实现的.而如今c++20即将带着concept,Ranges等新特性一同到来,不得 ...

  3. CEPH RGW多 ZONE的配置

    相关的名称解释 Region :可以理解为区域,是基于地理位置的逻辑划分:如:华南,华北之类,包含多个region的Ceph集群必须指定一个master region,一个region可以包含一个或者 ...

  4. python多线程与多进程及其区别

    个人一直觉得对学习任何知识而言,概念是相当重要的.掌握了概念和原理,细节可以留给实践去推敲.掌握的关键在于理解,通过具体的实例和实际操作来感性的体会概念和原理可以起到很好的效果.本文通过一些具体的例子 ...

  5. 同时启动多个tomcat,端口修改

    所用Tomcat服务器都为zip 版,非安装版.以 tomcat8 为例: 安装第二个Tomcat完成后,打开 tomcat/conf/server.xml 文件,查找以下三处: 1. 修改http访 ...

  6. pycharm的安装配置及思维导图

    1.1 计算机基础知识 主板:人的骨架,用于扩展设备的 cpu:人的大脑,用于计算和逻辑处理的 硬盘:存储数据(永久存储) 电源:人的心脏 内存:存储数据(临时存储) 断电即消失 操作系统 xp wi ...

  7. JDK集合面试20问

    1. HashMap的内部实现原理是什么? HashMap内部实现原理是数组+链表,通过散列算法将key值散列到数组中,如果到相同的位置,则通过拉链法解决散列冲突.在JDK8中新增了红黑树结构,当Ha ...

  8. .net测试篇之测试神器Autofixture基本配置一

    系列目录 实际工作中我们需要的数据逻辑万千,千变万化,而AutoFixture默认是按照一定算法随机生成一些假数据,虽然这在多数时候是ok的,但是可能不能满足我们的所有业务场景,有些时候我们需要进行一 ...

  9. Laravel框架内实现api文档:markdown转为html

    前后端分离的工作模式于今是非常流行了,前后端工作的对接,就离开不了API文档的辅助. 根据自己以往的工作经历,以及了解的一些资讯,API文档的建立,无非以下几种方式: 1. word文档模板 2. 第 ...

  10. mybatisX插件的使用

    MybatisX 插件 快捷         mapper方法生成对应-----> mapper.xml中 :ALT +enter