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. Splunk作为日志分析平台与Ossec进行联动

    背景: Ossec安装后用了一段时间的analogi作为ossec的报警信息显示平台,但是查看报警分类信息. 以及相关图标展示等方面总有那么一点点的差强人意,难以分析.因此使用逼格高一点的splunk ...

  2. Visaul Studio2015安装以及c++单元测试使用方法

    Visual Studio 2015安装流程     vs2015是一款十分好用的IDE,接下来就介绍一下安装流程.这里采用在线安装方式,从官网下载使得安装更加安全. 第一步:在百度中搜索Visual ...

  3. IEDA常用设置

    安装插件步骤省略,暂时不需要 IDEA菜单详解:基本有对应的快捷键或者是图标Help系列:Find Action:作用:快速新建文件,Ctrl + Shift + AHelp Topics:作用:帮助 ...

  4. git终端提示符

    最近使用git bash的时候,看到默认的终端提示符不爽,主要是太长了.所以想对git终端提示符进行优化 默认git的终端提示符会是  用户名@设备名称 ,我想改成更短的来查看. 提示符是由一个环境变 ...

  5. hdu 携程全球数据中心建设 (球面距离 + 最小生成树)

    题目 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib&g ...

  6. BootStrap图标

  7. WinDbg调试命令汇总

    一. 1. !address eax 查看对应内存页的属性 2. vertarget 显示当前进程的大致信息 3 !peb 显示process Environment Block 4. lmvm 可以 ...

  8. LeetCode Reverse Linked List (反置链表)

    题意: 将单恋表反转. 思路: 两种方法:迭代和递归. 递归 /** * Definition for singly-linked list. * struct ListNode { * int va ...

  9. HDU 1272 小希的迷宫 (水题)

    题意: 其实就是让你判断一个图是否为树,要求不能有孤立的点(没有这中情况),且只能有1个连通图,且边数+1=点数,且每个点都有边(不可能只有1个点出现). 思路: 有可能出现连续的4个0,也就是有测试 ...

  10. make menuconfig 出错

    运行 #make menuconfig HOSTLD scripts/kconfig/mconf scripts/kconfig/mconf.o: In function `main': mconf. ...