【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还是蓝名,真是菜的一笔,明年就大三了,马上就要毕业了,然而还是啥也不会,兼职和智障没什么两样,当初大一吹的牛逼说要成为学校 ...
随机推荐
- C结构体之位域(位段)(转)
有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C语言又提供了一种数据结构 ...
- 无法安装 golang.org/x/tools/的库
安装godep 官方的安装文档是使用go get github.com/tools/godep,很可惜,因为“网络”问题会报一个找不到golang.org/x/tools/go/vcs的错误. 而ht ...
- 手把手教你将本地项目文件上传至github
相信大家都听过Git(分布式版本号控制系统)和github吧.没听过也没关系(Google一下),反正以后要去公司肯定会听过. 我是在今年年初才接触Git.之后就一发不可收拾.仅仅要有比較好的项目就G ...
- 【git】强制覆盖本地代码
[git]强制覆盖本地代码(与git远程仓库保持一致) 2018年04月27日 23:53:57 不才b_d 阅读数:21145 版权声明:本文为博主不才b_d原创文章,未经允许不得转载. || ...
- caffe学习--cifar10学习-ubuntu16.04-gtx650tiboost--1g--01
引用了下文的资料,在此感谢! http://www.cnblogs.com/alexcai/p/5468164.html http://blog.csdn.net/garfielder007/arti ...
- nginx+thinkphp pathinfo模式配置
server { listen 81; server_name http://lanxing.cc gohosts.com; root "D:\WWW\lanxing\public" ...
- SAP-ABAP系列 第一篇SAP简介
第一篇 SAP简介 SAP全名为System Application and Products in Data Processing.SAP目前是全世界排名第一的RP软件,号称“全球最大的企业管理解决 ...
- iOS9新特性之新添加的关键字
iOS9 新出的关键字:用来修饰属性,或者方法的参数,返回值 好处:1.迎合swift 2.提高我们开发人员开发规范,减少程序员之间的交流 注意:iOS9新出的的关键字nonnull,nullable ...
- The threads in the thread pool will process the requests on the connections concurrently.
https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html Most of the executor implem ...
- Performance Tuning Using Linux Process Management Commands
[root@bigdata-server-02 /]# ps --help all Usage: ps [options] Basic options: -A, -e all processes -a ...