小伙捡了一沓钱
小伙捡了一沓钱,他以为捡的是美元,
反过来一看是冥币,小伙直呼真晦气,
这冥币只要你一碰,半夜女鬼来索命,
小伙撇嘴微微笑,转身来到一寺庙,
半夜女鬼真来到,发现自己中了套,
寺庙佛像金光闪,女鬼直接腿吓软,
佛骂女鬼神经病,你敢上寺庙来索命,
骂完觉得还不爽,还打出降龙十八掌。
不知过了多少天,女鬼重现人世间,
这次的目的就一个,找到小伙杀无赦,
小伙也是很鸡贼,知道自己要倒霉,
于是掏出新手机,打开了美团APP,
女鬼不知已上当,变成外卖小哥的模样,
顺着地址找上门,却吓的直接丢了魂,
外卖地址是纯敏山,里面全都是上仙,
上仙说女鬼太猖狂,敢来茅山耍流氓,
于是掏出桃木剑,一路火花带闪电。
不知过了多少天,女鬼再现人世间,
这次女鬼变小心,直接录了一段音,
这段录音很诡异,一听立马就嗝屁,
谁知小伙他不上当,把录音上传到网上,
接下来操作有点狠,把录音转发到日本,
隔天此事就上新闻,整个岛国变成了坟,
阎王此时也慌了神,咋死的全是日本人。
猜数字
#include<bits/stdc++.h>
using namespace std;
int main()
{
srand(time(0));
int l=1,r=100;
int x=rand()%r+l;
int a,ans=0;
cout<<"猜数字"<<endl<<"1-100"<<endl;
do
{
cin>>a;
if(a<=0 || a>100)
{
cout<<"你有病啊,重来"<<endl;
cout<<l<<"-"<<r<<endl;
}
else
{
if(a>x)
{
if(a-1<r) r=a-1;
cout<<"大了,"<<l<<"-"<<r<<endl;
}
else if(a<x)
{
if(a+1>l) l=a+1;
cout<<"小了,"<<l<<"-"<<r<<endl;
}
}
ans++;
if(ans>7) cout<<"你个大**,我*你*!别TM猜了!"<<endl;
}while(a!=x);
cout<<"你一共猜了"<<ans<<"次"<<endl<<endl;
if(ans>7)
{
cout<<"拉完了";
}
else if(ans>5)
{
cout<<"NPC";
}
else if(ans>3)
{
cout<<"彳亍";
}
else if(ans>1)
{
cout<<"蒸蚌";
}
else
{
for(int i=1;i<=13000;i++)
{
cout<<"误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误误"<<endl;
}
for(int i=1;i<=6500;i++)
{
cout<<"闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯闯"<<endl;
}
for(int i=1;i<=6500;i++)
{
cout<<"天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天"<<endl;
}
for(int i=1;i<=12000;i++)
{
cout<<"家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家家"<<endl;
}
cout<<" / | \\ _________ | | \\ _|___|_ 7-"<<endl;
cout<<" /____|_____ ___ _________ ______|______ __|__ ________ |___| /"<<endl;
cout<<" / | / |_________| _____|_____ | |___| /|______"<<endl;
cout<<" _______|_______ / _________ |___________| |/ \\ / __|___|__ | |"<<endl;
cout<<" | \\ |____|____| | | /| \\ / | |"<<endl;
cout<<" | / |____|____| / | / | / \\ / |"<<endl;
cout<<" | \\_______________ __/ |____| \\| __________ / \\ / |"<<endl;
}
return 0;
}
以下有关C++
C++头文件
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("apple.in","r",stdin);
freopen("apple.out","w",stdout);//大样例
return 0;
}快读
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int read()
{
int f=1,y=0;
char c;
c=getchar();
while(c<'0' || c>'9')
{
if(c=='-')
{
f=-1;
}
c=getchar();
}
while(c>='0' && c<='9')
{
y=y*10+c-'0';
c=getchar();
}
return y*f;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);//加速
int n;
n=read();
cout<<n;
return 0;
}堆
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000005];
void heapinsert(int pos)
{
int t=(pos-1)/2;
while(pos>0 && a[pos]<a[t])
{
swap(a[pos],a[t]);
pos=t;
t=(pos-1)/2;
}
}
void heapity(int pos,int r)
{
int t=pos*2+1;
while(t<r)
{
int best=(t+1<r&&a[t+1]<a[t])?t+1:t;
best=a[best]<a[pos]?best:pos;
if(best==pos){
break;
}
swap(a[best],a[pos]);
pos=best;
t=pos*2+1;
}
}
int main()
{
int n,op,size=0;
cin>>n;
while(n--)
{
cin>>op;
if(op==1)
{
int x;
cin>>x;
a[size]=x;
size++;
heapinsert(size-1);
}
else if(op==2)
{
cout<<a[0]<<endl;
}
else
{
swap(a[0],a[size-1]);
size--;
heapity(0,size);
}
}
return 0;
}差分
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int b[1005];
int he[1005];
int main()
{
int n,m,l,r,x;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>l>>r>>x;
b[l]+=x;
b[r+1]-=x;
}
for(int i=1;i<=n;i++)
{
he[i]=he[i-1]+b[i];
}
for(int i=1;i<=n;i++)
{
cout<<a[i]+he[i]<<" ";
}
return 0;
}二分答案
#include<iostream>
using namespace std;
long long n,k,l,r,mid,ans,p;
bool check(long long x)
{
if(cnt>n)
{
return true;
}
else
{
return false;
}
}
int main()
{
while(l<=r)
{
mid=(l+r)/2;
if(check(mid))
{
l=mid+1;
ans=mid;
}
else
{
r=mid-1;
}
}
cout<<ans<<endl;
return 0;
}单调队列
#include<iostream>
using namespace std;
int n,k,head,tail;
int a[1000005],qmin[1000005],qmax[1000005],mi[1000005],ma[1000005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
head=1;
tail=0;
for(int i=1;i<=n;i++)
{
while(head<=tail && i-qmin[head]+1>k)
{
head++;
}
while(head<=tail && a[qmin[tail]]>a[i])
{
tail--;
}
qmin[++tail]=i;
if(i>=k)
{
mi[i-k+1]=a[qmin[head]];
}
}
head=1;
tail=0;
for(int i=1;i<=n;i++)
{
while(head<=tail && i-qmax[head]+1>k)
{
head++;
}
while(head<=tail && a[qmax[tail]]<a[i])
{
tail--;
}
qmax[++tail]=i;
if(i>=k)
{
ma[i-k+1]=a[qmax[head]];
}
}
for(int i=1;i<=n-k+1;i++)
{
cout<<mi[i]<<' ';
}
cout<<endl;
for(int i=1;i<=n-k+1;i++)
{
cout<<ma[i]<<' ';
}
return 0;
}单调栈
#include<iostream>
using namespace std;
int n,top;
int a[3000006],st[3000006],ans[3000006];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=n;i>=1;i--)
{
while(top>0 && a[st[top]]<=a[i])
{
top--;
}
if(top==0)
{
ans[i]=0;
}
else
{
ans[i]=st[top];
}
st[++top]=i;
}
for(int i=1;i<=n;i++)
{
cout<<ans[i]<<' ';
}
cout<<endl;
return 0;
}ST表&RMQ问题
#include<bits/stdc++.h>
using namespace std;
int n,m,l,r,ans;
int lg[100005],a[100005],st[100005][20];
int read()
{
int y=0,f=1;
char ch;
ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while(ch>='0' && ch<='9')
{
y=y*10+ch-48;
ch=getchar();
}
return y*f;
}
int main(){
n=read();
m=read();
for(int i=1;i<=n;i++)
{
a[i]=read();
st[i][0]=a[i];
}
lg[1]=0;
for(int i=2;i<=n;i++)
{
lg[i]=lg[i/2]+1;
}
for(int j=1;j<=16;j++)
{
int len=1<<j;
for(int i=1;i<=n-len+1;i++)
{
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
for(int i=1;i<=m;i++)
{
l=read();
r=read();
int p=lg[r-l+1];
ans=max(st[l][p],st[r-(1<<p)+1][p]);
printf("%d\n",ans);
}
cout<<endl;
return 0;
}离散化
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100005],b[100005];
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=a[i];
}
sort(b+1,b+n+1);
int len=unique(b+1,b+n+1)-(b+1);
for(int i=1;i<=n;i++)
{
int pos=lower_bound(b+1,b+len+1,a[i])-b;
cout<<pos<<' ';
}
cout<<endl;
}
return 0;
}