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. ios(苹果公司的移动操作系统)

    iOS是由苹果公司开发的移动操作系统. 苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的, 后来陆续套用到iPod touch.iPad以及Appl ...

  2. 通过数据库表自动生成POJO(JavaBean)对象

    主类: package bqw.tool; import java.util.ResourceBundle;import java.sql.DriverManager;import java.sql. ...

  3. SQLserver临时表

    IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='#temp') DROP TABLE #tempGOSELECT ID,XM,ADDDW INTO #t ...

  4. Android开发之SmsManager和SmsMessage

    Android的手机功能(通话与短信)都放在android.telephony包中,到了4.4时(也就是API19)android.provider.Telephony及相关类横空出世辅助电话功能以及 ...

  5. [58 Argo]让argo跑起来

    接上一章,使用命令mvn jetty:run启动Argo,进入localhost的页面: 58在这里给了几种常见的访问和传值方法的示例,当点击到第三条<区分queryString和form参数& ...

  6. uva10375 Choose and divide

    唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...

  7. Qt之QTableView添加复选框(QAbstractTableModel)

    简述 使用QTableView,经常会遇到复选框,要实现一个好的复选框,除了常规的功能外,还应注意以下几点: 三态:不选/半选/全选 自定义风格(样式) 下面我们介绍一下常见的实现方式: 编辑委托. ...

  8. dom4j修改,获取,增加xml中某个元素的属性值

    XML文件: <?xml version="1.0" encoding="UTF-8"?> <vrvscript> <item I ...

  9. UVa 10870 (矩阵快速幂) Recurrences

    给出一个d阶线性递推关系,求f(n) mod m的值. , 求出An-dv0,该向量的最后一个元素就是所求. #include <iostream> #include <cstdio ...

  10. Asp.net 后台添加Meta标签方法

    Asp.net 后台添加Meta标签方法包括keywords,CSS.JS 下面是从Asp.net 后台添加CSS.JS.Meta标签的写法,我们这里写成函数方便以后使用.如果函数放在页面类中, Pa ...