奶牛看头发:
/*时间:2019.07.13*/
题链接:https://ac.nowcoder.com/acm/contest/984/A
题解:数组路径压缩或者单调栈
注意事项:longlong范围
C++输入加速:
/*时间:2019.07.14*/
long long read()
{
char ch=getchar();
long long x=0,f=0;
while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return f?-x:x;
}
multiset用法:
/*时间:2019.07.17*/
/* https://blog.csdn.net/sodacoco/article/details/84798621 */
插入一个数,删除一个数能够在O(logn)的时间内完成,时刻保证序列中数有序,序列中可以存在重复的数。
空间限制:C/C++ 32768K
32768K大小大概是:opt[2000][2000]+a[2000]+b[2000]
时间优化:
memset(opt,0,sizeof(opt));
/*
memset将会面临超时问题,
所以尽量使用int opt[200][200]={0};
*/
codeforces上超时原因分析:
longlong用int将会造成超时。
优先级队列:
/*2019.07.29*/
#include<queue>
struct node{
int x,y,v;
friend bool operator <(node a,node b){
return a.v<b.v;//大的优先级高
}
};
int main()
{
priority_queue<node>q;
q.push({1,2,5});
q.push({1,2,3});
return 0;
}
切长条:
题链接:https://ac.nowcoder.com/acm/contest/984/B
题解:以每段末尾位置sort
/*时间:2019.07.13*/
#include<bits/stdc++.h>
using namespace std;
struct node{
int a,b;
}f[10000010];
bool operator <(const node &x,const node &y){
return x.b<y.b||x.b==y.b&&x.a<y.a;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int b;
cin>>f[i].a>>b;
f[i].b=f[i].a+b;
}
sort(f+1,f+n+1);
int cnt=0,sum=0;
for(int i=1;i<=n;i++){
if(cnt<=f[i].a){
cnt=f[i].b;
sum++;
}
}
cout<<sum<<"\n";
return 0;
}
sam全称:后缀自动机
string的find函数时间复杂度是线性
set的find函数时间复杂度是logn
输出两个数,
第一个数为小数,小数部分两位,向右对齐,宽度为 6
第二个数为整数,向右对齐,宽度为 17
printf("%6.2lf%17d\n",x,y);
1e5就是 1*(10的5次方)即100000
5e7就是5*(10的7次方)即50000000
1e-5就是 1*(10的-5次方)即0.00001