【CQ18高一暑假前挑战赛5】标程
【A:暴力】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn],vis[maxn],N,M;
int main()
{
scanf("%d%d",&N,&M);
for(int i=;i<=M;i++){
scanf("%d",&a[i]);
vis[a[i]]=;
}
for(int i=;i<=N;i++)
if(!vis[i]) printf("%d\n",i);
return ;
}
【B:模拟】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
vector<short int>G[maxn];
int main()
{
int N,M,x,i,j;
scanf("%d%d",&N,&M);
for(i=;i<=N;i++)
for(j=;j<M;j++){
scanf("%d",&x); G[i].push_back(x);
}
printf("%d %d\n",M,N);
for(i=;i<M;i++){
for(j=;j<=N;j++) printf("%d ",G[j][i]);
printf("\n");
}
return ;
}
【C:数位DP入门题】
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
int N,L,a[maxn];
ll dp[maxn][][maxn],num[maxn][][maxn],ans;
void divede()
{
while(N){ a[++L]=N%; N/=; }
}
ll dfs(int pos,int lim,int x)
{
if(pos==){ num[pos][lim][x]=; return x==;}
if(!lim&&dp[pos][lim][x]) return dp[pos][lim][x];
int ups=lim?a[pos]:;
for(int i=;i<=ups;i++){
dp[pos][lim][x]+=(dfs(pos-,lim&(i==ups),i))+(x==?num[pos-][lim&(i==ups)][i]:);
num[pos][lim][x]+=num[pos-][lim&(i==ups)][i];
}
return dp[pos][lim][x];
}
int main()
{
scanf("%d",&N);
divede();
for(int i=;i<=a[L];i++) ans+=dfs(L-,i==a[L],i);
printf("%lld\n",ans);
return ;
}
【D:单调队列】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
const int inf=1e9+;
int a[maxn],L1[maxn],b[maxn],R1[maxn],L2[maxn],R2[maxn],q[maxn],head;
vector<int>G[maxn];
ll get(int u)
{
int Len=G[b[u]].size(); ll res=;
for(int i=;i<Len;i++){
if(u>=G[b[u]][i]){
ll r=min(R1[G[b[u]][i]],R2[u])-u+;
ll l=G[b[u]][i]-max(L2[u],L1[G[b[u]][i]])+;
if(r>&&l>) res+=l*r;
}
else {
ll r=min(R2[u],R1[G[b[u]][i]])-G[b[u]][i]+;
ll l=u-max(L2[u],L1[G[b[u]][i]])+;
if(r>&&l>) res+=l*r;
}
}
return res;
}
int main()
{
int N,i; ll ans=;
scanf("%d",&N);
for(i=;i<=N;i++) scanf("%d",&a[i]);
for(i=;i<=N;i++) scanf("%d",&b[i]);
a[]=inf; head=; q[head]=;
for(i=;i<=N;i++){ //若有相同,只算左边第一个。
while(head&&a[i]>a[q[head]]) head--;
L1[i]=q[head]+; q[++head]=i;
}
a[N+]=inf; head=; q[head]=N+;
for(i=N;i>=;i--){
while(head&&a[i]>=a[q[head]]) head--;
R1[i]=q[head]-; q[++head]=i;
}
for(i=;i<=N;i++) G[a[i]].push_back(i); b[]=inf; head=; q[head]=;
for(i=;i<=N;i++){
while(head&&b[i]>b[q[head]]) head--;
L2[i]=q[head]+; q[++head]=i;
}
b[N+]=inf; head=; q[head]=N+;
for(i=N;i>=;i--){
while(head&&b[i]>=b[q[head]]) head--;
R2[i]=q[head]-; q[++head]=i;
}
for(i=;i<=N;i++) ans+=get(i);
printf("%lld\n",ans);
return ;
}
【CQ18高一暑假前挑战赛5】标程的更多相关文章
- 【CQ18高一暑假前挑战赛4】标程
[二分或者STL] 二分: #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int main() { ,pos; s ...
- 【CQ18高一暑假前挑战赛3.5】标程
[A:快速幂相关] #include<bits/stdc++.h> using namespace std; int qpow(int a,int x){ a%=;; while(x){ ...
- 【CQ18高一暑假前挑战赛3】标程
[A:LCM] #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll a,b, ...
- 【CQ18高一暑假前挑战赛2】标程
[昨晚打校赛,5个小时打完很累了,所以搞忘出题了...对不起学弟们,不过出的题都亲自写过一遍,可以保证题目和代码长度都不长,题目难度不大] [A:bush博弈] #include<bits/st ...
- 【CQ18高一暑假前挑战赛1】标程
[A] #include<bits/stdc++.h> using namespace std; #define ll long long ll qpow(ll a,ll x,ll Mod ...
- [转]关于一些SPFA的标程
SPFA算法 求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm. 最短路径快速算法-SPFA算法是西南交通大学段凡丁于1994年发表的. 适用范围:给定 ...
- [求助][SPOJ MARIOGAM]-高斯消元(内含标程,数据等)
小蒟蒻开始做概率的题之后,遇到了这道题,然而,他发现自己的程序调试了无数次也无法通过,系统总是返回令人伤心的WA, 于是,他决定把这一天半的时间收集到的资料放在网上, 寻求大家的帮助, 也可以节省后来 ...
- hdu6435 Problem J. CSGO标程讲解以及改正标程的一个错误(本来第一个样例过不了2333) 以及 poj2926 五维曼哈顿距离模板
比赛的时候抄poj2926的模板,但改不来啊orz #include <iostream> #include <cstdio> #include <cstring> ...
- 暑假前的flag
暑假到了,为了简便新开了一个博客,供暑假刷体放一些题解,玩acm1年多了,cf还是蓝名,真是菜的一笔,明年就大三了,马上就要毕业了,然而还是啥也不会,兼职和智障没什么两样,当初大一吹的牛逼说要成为学校 ...
随机推荐
- win10安装 迅雷
下载安装文件所在目录 ,右键,选择以管理员身份运行,输入程序地址,如D:\download\ThunderMini_dl1.5.3.288.exe,回车,这样就出来了程序安装页面,之后就可以就行正常的 ...
- Dubbo zookeeper 初探
先把zookeeper在本地给安装好, 安装方法参考:http://blog.csdn.net/wxwzy738/article/details/16330253 这里的话讲述了两个工程一个工程是提供 ...
- C 标准库 - <errno.h>
C 标准库 - <errno.h> 简介 C 标准库的 errno.h 头文件定义了整数变量 errno,它是通过系统调用设置的,在错误事件中的某些库函数表明了什么发生了错误.该宏扩展为类 ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- 怎样隐藏Windows7 系统保留分区
安装Windows7操作系统时须要预留出100MB左右的系统保留盘分区.在Windows7激活是必须给它分配盘符,否则无法将其成功激活,但是激活后该盘符永久地显示了出来,怎样将其隐藏掉呢? 1.隐藏前 ...
- Solaris Samba服务器与DNS服务
用于文件传输的协议,类似于ftp,ssh,只是它比其他两个好用. Samba协议 NetBIOS :一种编程接口. SMB:server message block .主要作为Microsoft网络通 ...
- 设置安卓开机动画、开机logo
我们要修改的是system>media文件夹下的bootanimation.zip(手机开机动画)这个文件 先来讲讲这个文件结构:该zip解压后得到两个文件, 第一个目录存放了开机时播放的图片( ...
- JavaScript插件编写指南
在编写插件之前,大家要先了解做插件的几个要点: 插件需要满足的条件 一个可复用的插件需要满足以下条件: 插件自身的作用域与用户当前的作用域相互独立,也就是插件内部的私有变量不能影响使用者的环境变量: ...
- com关于IUnknown接口
com定义的每个接口都必须从IUnknown继承过来,主要原因是IUnknown接口提供了两个很重要的特性:生存期控制和接口查询. 客户程序仅仅能通过接口与com对象进行通信.尽管客户程序能够无论对象 ...
- poj3211 Washing Clothes
Description Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a ...