T1 请问这还是纸牌游戏吗 https://scut.online/p/567

这道题正解据说是方根 这里先放着等以后填坑吧qwq

但是由于这道题数据是随机的 所以其实是有各种水法的(但是我比赛根本没有想到任何水法qwq

第一种水法呢 因为数据随机 所以当数据大小变得比较大的时候 基本乘出来的数已经能覆盖1到P-1了 所以我们直接输出1和P-1就可以了

而数据比较小的时候就可以暴力计算了qwq

include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
using namespace std;
const int M=2e6+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
LL mod,n,m;
int v1[M],v2[M],cnt1,cnt2;
LL h1[M],h2[M];
int main(){
LL x;
mod=read(); n=read(); m=read();
for(int i=;i<=n;i++){
x=read();
if(!v1[x]) v1[x]=,h1[++cnt1]=x;
}
for(int i=;i<=m;i++){
x=read();
if(!v2[x]) v2[x]=,h2[++cnt2]=x;
}
if(cnt1*cnt2>(5e7)){printf("1 %d\n",mod-); return ;}
LL ans1=mod-,ans2=;
for(int i=;i<=cnt1;i++)
for(int j=;j<=cnt2;j++){
ans1=min(ans1,h1[i]*h2[j]%mod);
ans2=max(ans2,h1[i]*h2[j]%mod);
}
printf("%lld %lld\n",ans1,ans2);
return ;
}

第二种写法呢 我们就可以从枚举P-1开始枚举答案最大是多少 然后枚举每一个a i 看是否存在b i 使得ab%P==枚举的答案

这里利用费马小定理预处理好了每一个a i对应的逆元fv i 所以可以根据枚举的答案和a i直接计算出b所对应的值

然后判断这个值是否存在就可以啦

这样子写的话想要卡掉其实是非常困难的 因为如果答案在中间部分(需要枚举大概n/2次答案()

那么一定会存在很多重复的数 而我们一开始就可以先把重复数去掉(也就是去重)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
using namespace std;
const int M=2e6+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
LL mod,n,m;
int v1[M],v2[M],cnt1,cnt2;
LL h1[M],h2[M],fv[M];
LL qmod(LL a,LL b){
LL ans=;
while(b){
if(b&) ans=ans*a%mod;
b>>=;
a=a*a%mod;
}
return ans;
}
int main(){
LL x,ans1,ans2,f;
mod=read(); n=read(); m=read();
for(int i=;i<=n;i++){
x=read();
if(!v1[x]){
v1[x]=;
h1[++cnt1]=x;
fv[i]=qmod(x,mod-);
}
}
for(int i=;i<=m;i++){
x=read();
if(!v2[x]) v2[x]=,h2[++cnt2]=x;
}
for(f=,ans1=;;ans1++){
for(int i=;i<=cnt1;i++)
if(v2[ans1*fv[i]%mod]){f=; break;}
if(f) break;
}
for(f=,ans2=mod-;;ans2--){
for(int i=;i<=cnt1;i++)
if(v2[ans2*fv[i]%mod]){f=; break;}
if(f) break;
}
printf("%lld %lld\n",ans1,ans2);
return ;
}

T2 请问你喜欢跑步吗 https://scut.online/p/568

这道题就很明显是道水题了 找出每秒所有面包店中价值最大的面包 然后求和就可以了

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#define LL long long
#define lowbit(x) x&-x
using namespace std;
const int M=;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,m;
LL ans,s[M][M],k[M][M];
int main(){
n=read(); m=read();
for(int i=;i<=n;i++) for(int j=;j<=m;j++) s[i][j]=read();
for(int i=;i<=m;i++){
LL sum=;
for(int x=;x<=n;x++) sum=max(sum,s[x][i]);
ans+=sum;
}
printf("%lld\n",ans);
return ;
}

T3 请问穿着熊厉害吗 https://scut.online/p/569

这道题枚举到 √n就可以了

n到n-1 会对应大于 √n的另一段 具体的话通过手动模拟应该能有所体会 细节还是蛮多的

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#define LL long long
using namespace std;
LL read(){
LL ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
LL T,n,q,ans,last,G,x;
int main(){
T=read();
while(T--){
n=read();
if(n==){puts(""); continue;}
q=*n; ans=q+n; last=n;
//printf("%lld\n",ans);
for(x=;x*x<=q;x++){
ans+=q/x;
if(q%x) G=q/x;
else G=q/x;
ans=ans+(x-)*(last-G);
//printf("%d %d\n",last,G);
last=G;
}
ans+=(last-x+)*(x-);
printf("%lld\n",ans);
//printf("%lld %lld\n",last,x);
}
return ;
}

T4 请问机关锁打得开吗 https://scut.online/p/570

这道题9个锁 每个锁4种状态 一共也就2^18种状态 利用二进制来表示每一种状态

比如第一位和第二位表示第一个锁的状态也就是

00表示状态1

01表示状态2

10表示状态3

11表示状态四

以此类推 然后用bfs扫一遍就可以得到答案了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define LL long long
using namespace std;
const int Q=,P=(<<)+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int S,p[Q],s[Q][Q];
int G(int k,int x){
int w=;
if(k&(<<(*x))) w+=;
if(k&(<<(*x-))) w+=;
return w;
}
void nsp(int &k,int x,int w){
if(k&(<<(*x))) k-=(<<(*x));
if(k&(<<(*x-))) k-=(<<(*x-));
if(w&) k+=(<<(*x-));
if(w&(<<)) k+=(<<(*x));
}
int vis[P],d[P],ans=-;
queue<int>q;
void bfs(){
q.push(S); vis[S]=; d[S]=;
while(!q.empty()){
int MM=q.front(); q.pop();
if(!MM){ans=d[MM]; break;}
for(int x=;x<=;x++){
int M=MM,w=G(M,x),T=s[x][w],l=G(M,T);
w=(w+)%; l=(l+)%;
nsp(M,x,w); nsp(M,T,l);
if(!vis[M]) vis[M]=,d[M]=d[MM]+,q.push(M);
}
}
}
int main(){
for(int i=;i<=;i++){
p[i]=read()-;
for(int j=;j<=;j++) s[i][j]=read();
}
for(int i=;i<=;i++) nsp(S,i,p[i]);
bfs(); printf("%d\n",ans);
return ;
}

T5 请问直方图里能画矩形吗 https://scut.online/p/571

这道题的话 对每一个位置 找出他向左向右所能延申的最远距离就好了

可以用单调栈维护

考虑向左的延申的情况 我们考虑从1位置扫到i(当前)位置

如果一个位置j 他的高度h【j】比你大 并且他位置在你之前(j<I)那么他就可以被忽略

因为要从右边经过你的话 最大高度也就只能是h【i】

向右同理

通过这样的方法我们就可以维护出每一个点向左向右所能延申的最远距离了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define LL long long
using namespace std;
const int M=1e6+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
LL n,h[M],stk[M],top,l[M],r[M],ans;
int main(){
n=read();
stk[]=;
for(int i=;i<=n;i++) h[i]=read();
for(int i=;i<=n;i++){
while(top&&h[stk[top]]>=h[i]) top--;
l[i]=stk[top]+;
stk[++top]=i;
//for(int x=1;x<=top;x++) printf("%d ",h[stk[x]]); puts("");
}
top=; stk[]=n+;
for(int i=n;i>=;i--){
while(top&&h[stk[top]]>=h[i]) top--;
r[i]=stk[top]-;
stk[++top]=i;
}
//for(int i=1;i<=n;i++) printf("%d %d\n",l[i],r[i]);
for(int i=;i<=n;i++) ans=max(ans,(r[i]-l[i]+)*h[i]);
printf("%lld\n",ans);
return ;
}

当然我比赛的时候脑子一抽就用了set维护

就是将所有的点按从小到大排序 然后从最小开始枚举 将枚举到的点的位置丢到set的里面

这样到当前点时 所有高度比他小的点就已经被丢到set里面的 你就只需要找位置离你最近的点是谁就好了

这个用lower_bound实现的okay了 当然这样写复杂度要多一个log

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#define LL long long
using namespace std;
const int M=1e6+;
LL read(){
LL ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
LL n,r[M],ans,sum[M],l[M];
struct node{LL id,h;}e[M];
bool cmp(node a,node b){return a.h==b.h?a.id<b.id:a.h<b.h;}
set<LL>q;
set<LL>::iterator It;
int main(){
n=read();
for(int i=;i<=n;i++) e[i].h=read(),e[i].id=i;
sort(e+,e++n,cmp);
for(int i=;i<=n;i++){
if(q.empty()) r[e[i].id]=n+;
else{
It=q.end();
if(*--It<e[i].id) r[e[i].id]=n+;
else r[e[i].id]=*q.upper_bound(e[i].id);
}
//sum[e[i].id]=e[i].h*(r[e[i].id]-e[i].id);
q.insert(e[i].id);
}
q.clear();
for(int i=;i<=n;i++){
if(q.empty()) l[e[i].id]=;
else{
It=q.end();
if(*--It<(-e[i].id)) l[e[i].id]=;
else l[e[i].id]=*q.upper_bound(-e[i].id)*-;
}
//sum[e[i].id]=e[i].h*(r[e[i].id]-e[i].id);
q.insert(-e[i].id);
}
//for(int i=1;i<=n;i++) printf("%d %d\n",l[i],r[i]);
for(int i=;i<=n;i++) sum[e[i].id]=e[i].h*(r[e[i].id]-l[e[i].id]-);
for(int i=;i<=n;i++) ans=max(ans,sum[i]);
printf("%lld\n",ans);
return ;
}

T5  留坑待补

T6 留坑待补

T7  请问这是鸽子吗 https://scut.online/p/574

这道题的话 一共就26种字母 我们考虑将26种字母单独维护

对于每个字母 用一个树状数组维护前缀一共有多少个相同的xx(x为当前字母)对 当然 如aaa算两对

xx对以后一个位置作为代表参与计算

然后每次修改则涉及四次修改  删除两次 插入两次 看是否有xx对被破坏 或者是否有xx对形成

然后询问的时候26种各求一次就okay了 当然求和的时候注意细节 如原本为aaaaa的一段

求后三个位置(即aaa)的aa对数时 求出来应为3对 但是因为第一个a的前一位被切断了 所以需要减去1 即为2对

这个细节在求和时是需要注意的

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#define LL long long
#define lowbit(x) x&-x
using namespace std;
const int M=1e6+,N=2e5+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
char c[M];
int m,n;
int s[][N];
void add(int w,int x,int v){
//printf("%d %d %d\n",w,x,v);
while(x<=n){
s[w][x]+=v;
x+=lowbit(x);
}
//for(int i=1;i<=n;i++) printf("%d ",s[w][i]); puts("");
}
int p_sum(int w,int x){
int ans=;
while(x) ans+=s[w][x],x-=lowbit(x);
return ans;
}
int main(){
scanf("%s",c+);
n=strlen(c+);
for(int i=;i<=n;i++) if(c[i]==c[i-]) add(c[i]-'a',i,);//puts("qwq");
//for(int i=1;i<=n;i++) printf("%d ",s[1][i]);
//printf("%d\n",p_sum(1,15));
int op,x,y,q;
m=read();
while(m--){
op=read(); x=read();
if(op==){
q=getchar();
if(c[x]==q) continue;
if(c[x]==c[x-]) add(c[x]-'a',x,-);
if(c[x]==c[x+]) add(c[x]-'a',x+,-);
c[x]=q;
if(c[x]==c[x-]) add(c[x]-'a',x,);
if(c[x]==c[x+]) add(c[x]-'a',x+,);
}
else{
y=read();
int ans=;
for(int i=;i<;i++){
int now=p_sum(i,y)-p_sum(i,x-);
//printf("%d %d\n",p_sum(i,y),p_sum(i,x-1));
if(now==&&c[x]==('a'+i)&&c[x]==c[x-]) now=;
if(now) ans+=;
}
printf("%d\n",ans);
}
}
return ;
}

T8 请问我可以用左手吗 https://scut.online/p/575

这道题就是单纯的高精度加法了

#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#define LL long long
#define lowbit(x) x&-x
using namespace std;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
char a[],b[],c[],d[];
int la,lb,lc,ld,mx,now;
int main(){
scanf("%s",a+); la=strlen(a+);
scanf("%s",b+); lb=strlen(b+);
scanf("%s",c+); lc=strlen(c+);
mx=max(la,lb); mx=max(lc,mx);
while(mx){
int sum=now;
mx--;
if(la) sum+=(a[la]-''),la--;
if(lb) sum+=(b[lb]-''),lb--;
if(lc) sum+=(c[lc]-''),lc--;
now=sum/;
d[++ld]=sum%;
}
if(now) d[++ld]=now;
for(int i=ld;i>=;i--) printf("%d",d[i]);
return ;
}

T9 请问你强吗 https://scut.online/p/576

这道题就是单纯判断某些字母的出现次数

https://scut.online/p/576

2019 年「计算机科学与工程学院」新生赛 暨ACM集训队选拔赛 # 1的更多相关文章

  1. 2019年华南理工大学软件学院ACM集训队选拔赛 Round1

    TIps: 1.所有代码中博主使用了scanf和printf作为输入输出  2.代码中使用了define LL long long 所以在声明变量的时候 LL其实就等价于long long 希望这两点 ...

  2. WAIC | 奇点云携「酷炫AI应用」亮相2019世界人工智能大会

    你是否还在疑惑“人工智能可否改变世界?” 那么,你该有一些危机感了. 机器视觉.自然语言处理.智能语音.机器人问诊.智慧驾驶……这些AI技术及应用早已渗入了我们日常生活的点滴. 29日,以「智联世界, ...

  3. iOS模式详解—「runtime面试、工作」看我就 🐒 了 ^_^.

    Write in the first[写在最前] 对于从事 iOS 开发人员来说,当提到 ** runtime时,我想都可以说出来 「runtime 运行时」和基本使用的方法.相信很多开发者跟我当初一 ...

  4. kettle并行运行时出现「Unknown error in KarafBlueprintWatcher」

    背景:在使用kettle 6进行大量数据并行抽取时,偶尔会出现「Unknown error in KarafBlueprintWatcher」的错误,详细的报错信息可以查看下面的代码块. ERROR: ...

  5. loj #6250. 「CodePlus 2017 11 月赛」找爸爸

    #6250. 「CodePlus 2017 11 月赛」找爸爸 题目描述 小 A 最近一直在找自己的爸爸,用什么办法呢,就是 DNA 比对. 小 A 有一套自己的 DNA 序列比较方法,其最终目标是最 ...

  6. 面试必备:高频算法题终章「图文解析 + 范例代码」之 矩阵 二进制 + 位运算 + LRU 合集

    Attention 秋招接近尾声,我总结了 牛客.WanAndroid 上,有关笔试面经的帖子中出现的算法题,结合往年考题写了这一系列文章,所有文章均与 LeetCode 进行核对.测试.欢迎食用 本 ...

  7. 「DevOps 转型与实践」沙龙回顾第一讲

    9 月 19 日,CODING 和中国 DevOps 社区联合举办的深圳第九届 Meetup 在腾讯大厦 2 楼多功能圆满结束.本次沙龙以 「DevOps 转型与实践」 为主题,4 位来自互联网.金融 ...

  8. 众安「尊享e生」果真牛的不可一世么?

    近日,具有互联网基因的.亏损大户(成立三年基本没盈利,今年二季度末亏损近4亿,你能指望它多厉害?).财产险公司—众安推出“尊享e生”中高端医疗保险(财险公司经营中高端医疗真的很厉害?真的是中高端医疗险 ...

  9. XCActionBar 「Xcode 中的 Alfred」

    下载地址:https://github.com/pdcgomes/XCActionBar 基本命令: (1)「command+shift+8」或者双击「command」键可以打开「动作输入框窗口」 ( ...

随机推荐

  1. SpringBoot 集成MyBatis 中的@MapperScan注解

    SpringBoot 集成MyBatis 中的@MapperScan注解 2018年08月17日 11:41:02 文火慢炖 阅读数:398更多 个人分类: 环境搭建 在SpringBoot中集成My ...

  2. vue回到顶部

    backTop() { var top = document.body.scrollTop || document.documentElement.scrollTop; this.duration - ...

  3. java 中Shallow Heap与Retained Heap的区别

    Shallow Size Shallow Size是对象本身占据的内存的大小,不包含其引用的对象.对于常规对象(非数组)的Shallow Size由其成员变量的数量和类型来定,而数组的ShallowS ...

  4. win7安装scrapy

    Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 )所设 ...

  5. django 项目创建使用

    1. web框架的本质: socket服务端 与 浏览器的通信 2. socket服务端功能划分: a. 负责与浏览器收发消息(socket通信) --> wsgiref/uWsgi/gunic ...

  6. ACM-ICPC 2015 Changchun Preliminary Contest J. Unknown Treasure (卢卡斯定理+中国剩余定理)

    题目链接:https://nanti.jisuanke.com/t/A1842 题目大意:给定整数n,m,k,其中1≤m≤n≤1018,k≤10, 然后给出k个素数,保证M=p[1]*p[2]……*p ...

  7. 查看Linux系统所对应的版本

    #cat /etc/issue 在CentOS下执行显示为:CentOS release 5.7 (Final)Kernel \r on an \m 或在Ubuntu下显示为:Ubuntu 11.04 ...

  8. tpcc-mysql测试mysql5.6 (EXT4文件系统)

    操作系统版本:CentOS release 6.5 (Final)  2.6.32-431.el6.x86_64 #1 内存:32G CPU:Intel(R) Xeon(R) CPU E5-2450 ...

  9. 前端每日实战:93# 视频演示如何用纯 CSS 创作一根闪电连接线

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/RBjdzZ 可交互视频 此视频是可 ...

  10. nodejs和npm之间的关系

    Node.js是JavaScript的一种运行环境,是对Google V8引擎进行的封装.是一个服务器端的javascript的解释器. 包含关系,nodejs中含有npm,比如说你安装好nodejs ...