A - Mike and Cellphone

问有没有多解,每个点按照给出的序列用向量法跑一遍

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
const int N=2e5+;
const int INF=0x3f3f3f3f;
char s[];
int a[],n;
int mp[][]={-,-,-,-,
-,,,,
-,,,,
-,,,,
-,-,,-
};
typedef pair<int,int> pii;
pii pos[];
bool judge(int num){
int x=pos[num].first,y=pos[num].second;
for(int i=;i<=n;++i){
int px=pos[a[i]].first-pos[a[i-]].first;
int py=pos[a[i]].second-pos[a[i-]].second;
x+=px;y+=py;
if(x<||x>||y<||y>)return false;
if(mp[x][y]==-)return false;
}
return true;
}
int main(){
scanf("%d%s",&n,s+);
if(n==){printf("NO\n");return ;}
for(int i=;i<=n;++i)
a[i]=s[i]-'';
for(int i=;i<=;++i){
for(int j=;j<=;++j){
if(mp[i][j]==-)continue;
pos[mp[i][j]].first=i;
pos[mp[i][j]].second=j;
}
}
bool flag=false;
for(int i=;i<=;++i)
if(i!=a[]&&judge(i)){flag=true;break;}
if(flag)printf("NO\n");
else printf("YES\n");
return ;
}

B - Mike and Shortcuts

可能有更优的办法,一看数据,dij最短路水过

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
const int N=2e5+;
const int INF=0x3f3f3f3f;
struct Edge{
int v,next;
LL w;
Edge(int a=,LL b=){v=a,w=b;}
bool operator<(const Edge &e)const{
return w>e.w;
}
}edge[N*];
int head[N],tot,n;
LL d[N];
void add(int u,int v,int w){
edge[tot].v=v;
edge[tot].w=w;
edge[tot].next=head[u];
head[u]=tot++;
}
priority_queue<Edge>q;
bool vis[N];
void dij(int s){
for(int i=;i<=n;++i)d[i]=INF,vis[i]=;
d[s]=,q.push(Edge(s,));
while(!q.empty()){
int u=q.top().v;
q.pop();
if(vis[u])continue;
vis[u]=;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
if(!vis[v]&&d[v]>d[u]+edge[i].w){
d[v]=d[u]+edge[i].w;
q.push(Edge(v,d[v]));
}
}
}
}
int main(){
scanf("%d",&n);
memset(head,-,sizeof(head));
for(int i=;i<=n;++i){
int x;scanf("%d",&x);
add(i,x,);
}
for(int i=;i<n;++i){
add(i,i+,);
add(i+,i,);
}
dij();
for(int i=;i<n;++i)printf("%I64d ",d[i]);
printf("%I64d\n",d[n]);
return ;
}

C - Mike and Chocolate Thieves

直接二分找就行,注意二分的移动

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
const int N=2e5+;
const int INF=0x3f3f3f3f;
LL judge(LL mid){
LL sum=;
for(LL i=;i<=;++i){
sum+=mid/(i*i*i);
}
return sum;
}
int main(){
LL m;
scanf("%I64d",&m);
LL l=,r=1ll*1e18,ret=-;
while(l<=r){
LL mid=(l+r)>>;
LL tmp=judge(mid);
if(tmp>m)r=mid-;
else if(tmp==m)ret=mid,r=mid-;
else l=mid+;
}
printf("%I64d\n",ret);
return ;
}

D - Friends and Subsequences

这个题,不知道是我线段树写残了,还是线段树常数大,死活超时,RMQ才过,哪天去学一发ZKW线段树的姿势吧

#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define For(i,j,n) for(int i=j;i<=n;i++)
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=2e5+;
const int maxn=;
const double eps=1e-; int a[N],b[N],MX[N][],MN[N][],n;
struct Tree
{
int l,r;
int mmax,mmin;
}tr[*N]; void build(int o,int L,int R)
{
for(int i=;i<=n;i++)
MX[i][]=a[i],MN[i][]=b[i];
for(int j=;(<<j)<=n;j++)
{
for(int i=;i+(<<j)-<=n;i++)
{
MX[i][j]=max(MX[i][j-],MX[i+(<<(j-))][j-]);
MN[i][j]=min(MN[i][j-],MN[i+(<<(j-))][j-]);
}
}
}
int query(int o,int L,int R,int flag)
{
if(flag)
{
int k = ;
while( (<<(k+)) <= R-L+) k ++ ;
return max(MX[L][k],MX[R-(<<k)+][k]);
}
else
{
int k = ;
while( (<<(k+)) <= R-L+) k ++ ;
return min(MN[L][k],MN[R-(<<k)+][k]);
}
}
int judge(int x,int y)
{
int mx=query(,x,y,),mn=query(,x,y,);
if(mx==mn)return ;
else if(mx>mn)return ;
return ; }
int main()
{
read(n);
For(i,,n)read(a[i]);
For(i,,n)read(b[i]);
build(,,n);
LL ret=;
for(int i=;i<=n;++i){
int ans1=-,ans2=-;
int l=i,r=n;
while(l<=r){
int m=l+r>>;
int t=judge(i,m);
if(t==)ans1=m,r=m-;
else if(t==)r=m-;
else l=m+;
}
l=i,r=n;
while(l<=r){
int m=l+r>>;
int t=judge(i,m);
if(t==)ans2=m,l=m+;
else if(t==)r=m-;
else l=m+;
}
if(ans1!=-&&ans2!=-)ret+=ans2-ans1+;
}
printf("%I64d\n",ret);
return ;
}

E - Mike and Geometry Problem

区间题,转化一下,看每个点被多少个线段覆盖(离散化搞搞),相同覆盖数统计,然后用组合数就行

#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N=2e5+;
const LL mod=1e9+;
struct Segment{
int l,r;
}p[N];
int pos[N*],n,k,tot,a[N*],b[*N];
LL dp[N],fac[N],inv[N];
LL quick_pow(LL a,LL num){
LL ret=;
while(num){
if(num&)ret=(ret*a)%mod;
num>>=;
a=(a*a)%mod;
}
return ret;
}
LL C(LL n,LL m){
return (fac[n]*inv[n-m])%mod*inv[m]%mod;
}
int main()
{
scanf("%d%d",&n,&k);
inv[]=fac[]=;
for(int i=;i<=n;++i){
fac[i]=1ll*i*fac[i-]%mod;
inv[i]=quick_pow(fac[i],mod-);
}
for(int i=;i<=n;++i){
scanf("%d%d",&p[i].l,&p[i].r);
pos[++tot]=p[i].l;
pos[++tot]=p[i].r;
}
sort(pos+,pos++tot);
tot=unique(pos+,pos++tot)-pos-;
for(int i=;i<=n;++i){
p[i].l=lower_bound(pos+,pos++tot,p[i].l)-pos;
p[i].r=lower_bound(pos+,pos++tot,p[i].r)-pos;
++a[p[i].l],--b[p[i].r];
}
for(int i=;i<=tot;++i){
a[i]+=a[i-];
++dp[a[i]];
if(i!=)dp[a[i-]]+=max(,pos[i]-pos[i-]-);
a[i]+=b[i];
}
LL ret=;
for(int i=k;i<=n;++i){
ret=(ret+dp[i]*C(i,k)%mod)%mod;
}
printf("%I64d\n",ret);
return ;
}

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

  1. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  2. Codeforces Round #369 (Div. 2) 套题

    A:模拟水题不说 #include <iostream> #include <string.h> #include <algorithm> #include < ...

  3. Codeforces Round #367 (Div. 2) 套题

    吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include & ...

  4. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  5. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  6. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  7. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  8. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

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

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

随机推荐

  1. 彷徨中的成长-记一个文科生的IT成长过程

    纠结了许久,要不要写这篇文章,然而最终还是写了.就权当总结与呻吟吧..当然,呻吟最开始还是发在自己的站点的,忍不住手贱,还是想发博客园. 1 剧透 人算不如天算:时隔多年,我竟然搞起了前端. 2 发端 ...

  2. codeforces div.1 A

    A. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. 在sklearn上读取人脸数据集保存图片到本地

    程序如下: # -*- coding: utf-8 -*- """ Created on Sat Oct 31 17:36:56 2015 ""&qu ...

  4. 保障视频4G传输的流畅性,海康威视摄像头相关设置

    我们目前的rtsp视频解决方案如下: 摄像头<---------->NVR(通过4G上传)<---------->easydarwin<---------->自己的 ...

  5. Sina App Engine(SAE)教程(11)- Yaf使用

    Yaf参考资料 Yaf(Yet Another Framework)用户手册 想在SAE使用Yaf? 无需申请,sae环境已经全面支持. Yaf 实战 下面是一个运行在SAE的Yaf的hello wo ...

  6. python url编码,解码

    >>> urllib.unquote('%E4%B8%BD%E6%B1%9F') >>> data '\xe4\xb8\xbd\xe6\xb1\x9f' >& ...

  7. 每用户订阅上的所有者 SID 不存在 (异常来自 HRESULT:0x80040207)

    出现这个问题是因为pQueryFilter.WhereClause = "RoomNumber=" +cmbFromPoint.SelectedItem;中的cmbFromPoin ...

  8. 41. First Missing Positive

    题目: Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2 ...

  9. Nmap扫描原理与用法

    Nmap扫描原理与用法 1     Nmap介绍 Nmap扫描原理与用法PDF:下载地址 Nmap是一款开源免费的网络发现(Network Discovery)和安全审计(Security Audit ...

  10. linux下手动安装apache详解

    引自:http://blog.chinaunix.net/uid-28458801-id-4211258.html error1:出现以下错误时候,需要下载安装apr configure: error ...