DAY 7

预计得分:40+80+0 100+100+10
实际得分:40+60+0 100+100+10

上午很杯具,一二题O(nlogn)写完就对拍一下,然后发现T2RE了,然后不RE了之后试试大样例
然后不对,然后调到几乎考试结束,最后试着输出字符串的长度,发现长度不对,诶???
然后用文件读入输出,然后才发现我一直是对的……在控制台中字符串会读不完……
然后就没来得的写第一题的比较快的nlogn算法,我用的multiset,虽然复杂度正确
但是会因为STL巨大的常数超时成煞笔,早知道不老调T2了……
其实T1和T2都因为STL巨大的常数TLE
但是第二题不用的话我就得手写树状数组或者平衡树了,不如写STL吧
T2用hash二分排序不会MLE

下午还好,T1T2都很简单
所以水水就过去了
但是T2的eps改了5次,从1e-5到1e-9幸好有对拍
本来写的N^4,担心会超时所以预处理一下优化掉几乎所有的时间开销
其实多此一举了,本来就是正解

上午和下午的T3都是状压dp,并不是很想做而且不是很会做所以都没做

困呢……
上午T2

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<cctype>
#include<cstdio>
#include<string>
#include<cstdio>
#include<ctime>
#define N 50005
using namespace std;
 
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch))    
        ch=getchar();
    while(isdigit(ch))
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
 
vector<string>a[27];
void insert(string x,int i){
    a[i].insert(upper_bound(a[i].begin(),a[i].end(),x),x);
    return;
}
int find(string x,int i){
    return upper_bound(a[i].begin(),a[i].end(),x)-a[i].begin()+1;
}

int ans;
int n,m;
string str;
int sum[N];

int main(){
    freopen("sort_big.in","r",stdin);
   freopen("sort.out","w",stdout);
   int t=clock();
  for(int i=0;i<26;++i)
       a[i].reserve(500005*m);
    n=read(),m=read();
    cin>>str;
    string now;
    int len=str.size();
    for(int i=0;i<len;++i){
        if(i+m-1>len-1)
            now=str.substr(i,len-i);
        else now=str.substr(i,m);
        int shou=now[0]-'a';
        for(int j=shou;j<26;++j)ans+=sum[j];
        ans-=find(now,shou);
        insert(now,shou);
        sum[shou]++;
    }
    printf("%d
",ans);    printf("%lf",1.*(clock()-t)/CLOCKS_PER_SEC);   
    return 0;
}

下午T2

#include<iostream>
#include<cstdio>
#define eps 1e-9
#define N 105
using namespace std;

void read(int &s){
    char ch=getchar();
    for(;!isdigit(ch);ch=getchar());
    for(s=0;isdigit(ch);s=s*10+ch-'0',ch=getchar());
}

double abs(double s){
    return s>=0?s:-1.0*s;
}

bool d(double a,double b){
    if(abs(a-b)<=eps)return true;
    else return false;
}

double ran;
int l,r;
int n,c,k;
double s[N][N];
double f[N];
int cha[N];
int si[N];

int main(){
    freopen("paint.in","r",stdin);
    freopen("paint.out","w",stdout);
    read(n);
    read(c);
    read(k);
    s[0][1]=1.00;
    for(int i=1;i<=k;++i){
        read(l),read(r);
        cha[l]++;
        cha[r+1]--;
    }
    ran=(double)1.0/c;
    double ans=0.00;
    for(int i=1;i<=n;++i)
        si[i]=cha[i]+si[i-1];
    for(int p=1;p<=100;++p){
        for(int j=0;j<c;++j)f[j]=0.0;
        for(int j=0;j<c;++j){
            if(!d(s[p-1][j],0)){
                for(int k=0;k<c;++k){
                    f[(k*j)%c]+=s[p-1][j]*0.50*ran;
                }
            }
        }
        for(int j=0;j<c;++j)
            s[p][j]=s[p-1][j]*0.5+f[j];
    }    
    for(int i=1;i<=n;++i){
        for(int j=0;j<c;++j)
            ans+=s[si[i]][j]*j;
    }
    printf("%.3llf",ans);
    return 0;
}
原文地址:https://www.cnblogs.com/qdscwyy/p/7780650.html