A

脑筋急转弯

 // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = <<;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); //void fre() {
// freopen("in.txt","r",stdin);
//}
int vis[];
int ans[];
int main(){
int n;
string s;
cin>>n;
cin>>s;
clc(vis,);
clc(ans,);
for(int i=;i<s.length();i++) vis[s[i]-'']=true;
for(int i=;i<=;i++){
if(!vis[i]) continue;
if(i==||i==||i==) ans[]=;
if(i==||i==||i==||i==) ans[]=;
if(i==||i==||i==) ans[]=;
if(i==||i==||i==||i==) ans[]=;
}
printf("%s\n",ans[]&ans[]&ans[]&ans[]?"YES":"NO");
return ;
}

B - Mike and Shortcuts

从i到j的花费是fabs(j-i)

现在每个点有一条路ai,可以使得i走到ai的花费为1

现在问你从1走到i点的花费是多少

搜索i点前后两个点

 // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); //void fre() {
// freopen("in.txt","r",stdin);
//}
int a[N];
int ans[N];
int vis[N];
int n;
struct Node{
int x,w;
Node(int a,int b):x(a),w(b){}
};
void bfs(){
queue<Node>q;
q.push(Node(,));
while(!q.empty()){
Node f=q.front();
q.pop();
if(vis[f.x]) continue;
vis[f.x]=true;
ans[f.x]=f.w;
if(!vis[a[f.x]])
q.push(Node(a[f.x],f.w+));
if(!vis[f.x+]&&(f.x+)<=n)
q.push(Node(f.x+,f.w+));
if(!vis[f.x-]&&(f.x-)>=)
q.push(Node(f.x-,f.w+));
}
}
int main(){
// int n;
cin>>n;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
bfs();
for(int i=;i<=n;i++){
printf("%d%c",ans[i],i!=n?' ':'\n' );
}
return ;
}

C - Mike and Chocolate Thieves

题意:

求一个数,恰好可以分成n个(a.ak.ak^2.ak^3)的形式。且符合条件最小的数。。看样列yy一下题意。。

思路:直接二分答案

 // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = <<;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); //void fre() {
// freopen("in.txt","r",stdin);
//}
LL n;
LL cube(LL x){
return x*x*x;
}
LL fun(LL k){
LL sum=;
for(int i=;i<=1e6;i++){
if(cube(i)>k) break;
sum+=k/cube(i);
}
return sum;
}
int main(){
cin>>n;
LL l=,r=1e18;
LL mid;
while(l<=r){
mid=(l+r)>>;
if(fun(mid)>=n) r=mid-;
else l=mid+;
}
if(fun(r+)==n) printf("%I64d\n",r+);
else printf("-1\n");
return ;
}

D - Friends and Subsequences

题意:a b两个数组,[l,r]上,a的最大值等于b的最小值,问有几个这样区间

思路:首先一看这种题肯定是二分来做。

枚举l,二分r。a数组中最大值肯定是非递减的,b最小值肯定是非递增的。所以二分r的时候,根据这个性质。

两次二分,二分r的极右端,极左端需要技巧。看代码。

求区间最大值可以用rmq,O(n*logn+1);

线段树查询时(logn),也可以。

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int a[N],b[N];
int maxa[N][],minb[N][]; void init(int n){
int i,j;
for(i=;i<n;i++){
maxa[i][]=a[i];
minb[i][]=b[i];
}
for(j=;(<<j)<=n;j++)
for(i=;i+(<<j)-<n;i++){
maxa[i][j]=max(maxa[i][j-],maxa[i+(<<(j-))][j-]);
minb[i][j]=min(minb[i][j-],minb[i+(<<(j-))][j-]);
}
} int rmq(int l,int r,int c)
{
int k=;
while((<<(k+))<=r-l+) k++;
if(c)
return max(maxa[l][k],maxa[r-(<<k)+][k]);
else
return min(minb[l][k],minb[r-(<<k)+][k]);
} int main() {
// fre();
int n;
scanf("%d",&n);
for(int i=; i<n; i++)
scanf("%d",&a[i]);
for(int i=; i<n; i++)
scanf("%d",&b[i]);
init(n);
LL ans=;
for(int i=; i<n; i++) {
int l=i,r=n-;
int rmin,rmax;
bool flag=;
while(l<=r) {
int mid=(l+r)>>;
int ans_a=rmq(i,mid,);
int ans_b=rmq(i,mid,);
if(ans_a==ans_b){
flag=;
}
if(ans_a>ans_b){
r=mid-;
}
else
l=mid+;
}
if(!flag) continue;
rmax=r;
l=i;
while(l<=r){
int mid=(l+r)>>;
int ans_a=rmq(i,mid,);
int ans_b=rmq(i,mid,);
if(ans_a<ans_b)
l=mid+;
else
r=mid-;
}
rmin=l;
ans+=(LL)(rmax-rmin+);
}
printf("%I64d\n",ans);
return ;
}

E - Mike and Geometry Problem

题意:k个区间,求C(k,n)个区间的交集

思路:数据太大显然不能直接暴力。区间交集等价与每个点被覆盖了几次,最后答案就是每个点覆盖的次数C(nex,n)求和。

lucas超时,费马小。。。

统计每个点被覆盖的次数类似扫描线处理离线化树状数组

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-); void fre() {
freopen("in.txt","r",stdin);
} // inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
LL fac[N]; LL qpow(LL a,LL b)
{
LL ans=;a%=MOD;
for(LL i=b;i;i>>=,a=a*a%MOD)
if(i&) ans=ans*a%MOD;
return ans;
} LL Comb(LL n,LL m){
if(m>n||m<) return ;
LL s1=fac[n],s2=fac[n-m]*fac[m]%MOD;
return s1*qpow(s2,MOD-)%MOD;
}
int main(){
int k,n;
fac[]=;
fac[]=;
for(int i=;i<N;i++)
fac[i]=fac[i-]*i%MOD;
scanf("%d%d",&k,&n);
vector<pair<int,int> >p;
for(int i=;i<k;i++){
LL r,l;
scanf("%I64d %I64d",&l,&r);
p.push_back(make_pair(l-,));
p.push_back(make_pair(r,-));
}
sort(p.begin(),p.end());
LL ans=;
int nex=,last=;
for(int i=;i<(int)p.size();i++){
ans=(ans+Comb(nex,n)*(p[i].first-last))%MOD;
nex+=p[i].second;
last=p[i].first;
}
printf("%I64d\n",ans);
return ;
}

Codeforces Round #361 (Div. 2)的更多相关文章

  1. Codeforces Round #361 (Div. 2) C.NP-Hard Problem

    题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. ...

  2. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合

    E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...

  3. Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分

    D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description Mike a ...

  4. Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...

  5. Codeforces Round #361 (Div. 2) B. Mike and Shortcuts bfs

    B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mi ...

  6. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  7. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

  8. Codeforces Round #361 (Div. 2) D

    D - Friends and Subsequences Description Mike and !Mike are old childhood rivals, they are opposite ...

  9. Codeforces Round #361 (Div. 2) C

    C - Mike and Chocolate Thieves Description Bad news came to Mike's village, some thieves stole a bun ...

  10. Codeforces Round #361 (Div. 2) B

    B - Mike and Shortcuts Description Recently, Mike was very busy with studying for exams and contests ...

随机推荐

  1. TCL语言笔记:TCL中的列表操作

    一.介绍 列表则是具有特殊解释的字符串.Tcl 中的列表操作和其它 Tcl 命令一样具有相同的结构.列表可应用在诸如 foreach 这样的以列表为变元的循环命令中,也应于构建 eval 命令的延迟命 ...

  2. Windows下gcc以及Qt的DLL文件调用之总结(三种方法)

    DLL与LIB的区别 :1.DLL是一个完整程序,其已经经过链接,即不存在同名引用,且有导出表,与导入表lib是一个代码集(也叫函数集)他没有链接,所以lib有冗余,当两个lib相链接时地址会重新建立 ...

  3. NSArray 数组排序

    //方法1,使用自带的比较器 //compare是数组自带的比较方法 NSArray *array=[NSArray arrayWithObjects:@"3",@"1& ...

  4. Retrofit分析-漂亮的解耦套路

    没耐心自己分析源码的同学,还可以参考Stay录制的视频版 Retrofit分析-漂亮的解耦套路(视频版) 万万没想到Retrofit会这么火,在没看源码之前,我简单的认为是因为它跟OkHttp同出一源 ...

  5. 协同滤波 Collaborative filtering 《推荐系统实践》 第二章

    利用用户行为数据 简介: 用户在网站上最简单存在形式就是日志. 原始日志(raw log)------>会话日志(session log)-->展示日志或点击日志 用户行一般分为两种: 1 ...

  6. MFC编程入门

    一. 什么是MFC? 如果你要建立一个Windows应用程序,应该如何下手? 好的开端是从设计用户界面开始. 首先,你要决定什么样的用户能使用该程序并根据需要来设置相应的用户界面对象.Windows用 ...

  7. HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询

    题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...

  8. EBS报表输出文件格式控制

    具体使用方法:1.添加用户参数p_conc_request_id2.在BeforeReport trigger中添加srw.user_exit('FND SRWINIT');          和Af ...

  9. bzoj2878

    又是环套树dp,这次不是我擅长的类型 首先考虑树上的暴力,肯定是穷举起点然后以起点为根dp 我们用g[i]表示以点i为期望走的路径总长,答案就是1/n*Σ(g[i]/d[i]) (d[i]表示点度数) ...

  10. UWP:本地应用数据

    获取应用的设置和文件容器 使用 ApplicationData.LocalSettings 属性可以获取 ApplicationDataContainer 对象中的设置. 注意:每个设置的名称最长可为 ...