【CQ18高一暑假前挑战赛1】标程
【A】
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll qpow(ll a,ll x,ll Mod){
a%=Mod; ll res=;
while(x){
if(x&) res=res*a%Mod;
a=a*a%Mod;
x>>=;
} return res;
}
int main()
{
ll a,b,c;
cin>>a>>b>>c;
a=qpow(a,b,c);
cout<<a<<endl;
return ;
}
【B】
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll N,ans;
cin>>N;
ans=N;
ans-=N/;
ans-=N/;
ans-=N/;
ans-=N/; ans+=N/(*);
ans+=N/(*);
ans+=N/(*);
ans+=N/(*);
ans+=N/(*);
ans+=N/(*); ans-=N/(**);
ans-=N/(**);
ans-=N/(**);
ans-=N/(**); ans+=N/(***);
cout<<ans<<endl;
return ;
}
【C】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char c[maxn];
int dp[maxn][maxn];
int main()
{
scanf("%s",c+);
int L=strlen(c+),i,j;
for(i=L;i>=;i--){
for(j=i;j<=L;j++){
if(j-i+==) dp[i][j]=;
else if(j-i+==) dp[i][j]=(c[i]==c[j]?:);
else {
dp[i][j]=min(dp[i+][j],dp[i][j-])+;
if(c[i]==c[j]) dp[i][j]=min(dp[i][j],dp[i+][j-]);
}
}
}
cout<<dp[][L]<<endl;
return ;
}
【D】
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn],rt[maxn],cnt;
struct node{
int l,r,val;
node(){ l=r=val=; }
node(int L,int R,int V):l(L),r(R),val(V){}
}s[maxn*];
void add(int &now,int pre,int x,int pos)
{
now=++cnt;
s[now]=node(s[pre].l,s[pre].r,s[pre].val+);
if(pos==-) return ;
if(((x>>pos)%)==) add(s[now].l,s[pre].l,x,pos-);
else add(s[now].r,s[pre].r,x,pos-);
}
int query(int now,int pre,int x)
{
int res=;
for(int i=;i>=;i--){
int t=(x>>i)%;
if(t==){
if(s[now].r&&s[s[now].r].val-s[s[pre].r].val>) now=s[now].r, pre=s[pre].r, res+=(<<i);
else if(s[now].l) now=s[now].l, pre=s[pre].l;
else break;
}
if(t==){
if(s[now].l&&s[s[now].l].val-s[s[pre].l].val>) now=s[now].l, pre=s[pre].l, res+=(<<i);
else if(s[now].r) now=s[now].r, pre=s[pre].r;
else break;
}
}
return res;
}
int main()
{
int N,Q,L,R,x,i;
scanf("%d%d",&N,&Q);
for(i=;i<=N;i++){
scanf("%d",&a[i]);
add(rt[i],rt[i-],a[i],);
}
for(i=;i<=Q;i++){
scanf("%d%d%d",&x,&L,&R);
int ans=query(rt[R+],rt[L],x);
printf("%d\n",ans);
}
return ;
}
【CQ18高一暑假前挑战赛1】标程的更多相关文章
- 【CQ18高一暑假前挑战赛5】标程
[A:暴力] #include<bits/stdc++.h> using namespace std; ; int a[maxn],vis[maxn],N,M; int main() { ...
- 【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 ...
- [转]关于一些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#应用程序配置文件.config介绍
我们经常会希望在程序中写入一些配置信息,例如版本号,以及数据库的连接字符串等.你可能知道在WinForm应用程序中可以利用Properties.Settings来进行类似的工作,但这些其实都利用了Ap ...
- 金山面试CDN
History 今天去金山网络面试的时候,被问到性能优化,我说了几个.最后说到了CDN,我说要尽量把静态的内容放置到CDN,可是为什么呢?面试官说既然你说到CDN.你就说说它的原理. 之前有看过,可是 ...
- SD卡操作相关的工具SDCardUtils
SD卡操作相关的工具 package com.flyou.utils; import java.io.File; import android.os.Environment; import andro ...
- react 自定义 TabBar 组件
1.创建 组件 src/components/TabBar/index.js /** * TabBar 组件 */ import React ,{ PureComponent } from 'reac ...
- angular 图片加载失败 情况处理? 如何在ionic中加载本地图片 ?
1.angular 图片加载失败 情况处理 在directive中定义组件,在ng-src错误时,调用err-src app.directive('errSrc',function(){ return ...
- 【分布式计算】DFS && BigTable
1.背景 分布式计算的发迹应该是google在2003年发表的三篇paper.各自是GFS.MapReduce.BigTable. 当中MapReduce大家都非常熟悉了.不懂的同学也能够看看我之前写 ...
- 在没有安装access的电脑上读写.mdb文件
在微软官方下载MDAC access数据库访问组件即可
- Python 模块之 ConfigParser: 用 Python 解析配置文件
在程序中使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在 Python 里更是如此,在官方发布的库中就包含有做这件事情的库,那就是 ConfigParser,这里简单的做 ...
- linux SPI驱动——简单的gpio模拟SPI驱动测试 (二)
1: /* 2: * Add by xuyonghong for duotin car radio fm 3: * Copyright (C) 2016-5-24 xuyonghong@duotin. ...
- Django框架学习——python模拟Django框架(转载)
原贴来源 http://wiki.woodpecker.org.cn/moin/ObpLovelyPython/AbtWebModules python实现web服务器 web开发首先要有web服务器 ...