头像

May_wind




离线:2天前



原题链接

#include<iostream>
#include<cstdio>

using namespace std;

double d,v,o,dt[10],pt[10],ans,nl;
int n,j;
double dfs(int now){
    if(nl*o + dt[now] >= d)return 0.0;
    double t = v*o;
    if((d - dt[now] > t) || (dt[now+1]-dt[now] > t))return -1.0;
    int est = now,minn = pt[now],er;
    double cost = 0.0;
    j = now;
    while(dt[j]-dt[now] <= t && j <= n)j ++;
    j--;
    for(int i = now+1 ; i <= j ; i ++){
        if(pt[i] < minn){
            minn = pt[i];
            est = i;
        }
    }
    if(est == now){
        if(v*o + dt[now] >= d)return (d-dt[now]-nl*o)/o*pt[now];
        est = now+1;minn = pt[now+1];
        for(int i = now+1 ; i <= j ; i ++){
            if(pt[i] < minn){
                minn = pt[i];
                est = i;
            }
        }   
        if(nl*o + dt[now] >= dt[est])cost = 0;
        else cost = (dt[est]-dt[now]-nl*o)/o*pt[now];
        double a = dfs(est);
        if(a == -1.0)return -1.0;
        return cost += a;
    }
    else{
        for(int i = now+1 ; i <= j ; i ++){
            if(pt[i] < pt[now]){
                er =i;break;
            }
        }
        if(nl*o + dt[now] >= dt[er])cost = 0;
        else cost = (dt[er]-dt[now]-nl*o)/o*pt[now];
        double a = dfs(er);
        if(a == -1.0)return -1.0;
        return cost += a;
    }
}
int main(){
    scanf("%lf%lf%lf%lf%d",&d,&v,&o,&pt[0],&n);
    for(int i = 1 ; i <= n ; i ++)scanf("%lf%lf",&dt[i],&pt[i]);
    ans = dfs(0);
    if(ans == -1.0)printf("No Solution");
    else printf("%.2lf",ans);
    return 0;
}

样例没过,然而玄学得了50分(
大佬们求助,蒟蒻在此万分感谢




May_wind
15天前

大佬们求助

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
    string s;
    char s1[100];
    memset(s1,0,sizeof(s1));
    int len,j = 0;
    cin >> s;
    len = s.size();
    for(int i = 0 ; i < len ; i ++){
        if(i%2==0)
            if((s[i]>='A'&&s[i]<='Z'||(s[i]>='a'&&s[i]<='z'){
                s1[j] = s[i]+1;
                ++j;
            }
    }
    cout << s1 << endl;
    return 0
}

判断:输出的字符串只能是由字母组成()
若输入的字符串长度为0,则输出的字符串长度最长可能为()
A.4 B.5 C.6 D.10

判断题的答案是对,但是当某个s[i]等于z或Z时,输出里面不就会出现非字母的符号了?
选择题的题干意思是什么?

求解答。



活动打卡代码 AcWing 793. 高精度乘法

May_wind
2个月前
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>

using namespace std;

string a;
int x;
vector<int>A,B;
void mul(vector<int>A,int x){
    int t = 0;
    for(int i = 0 ; i < A.size() || t; i ++){
        if(i < A.size())t += A[i]*x;
        B.push_back(t%10);
        t /= 10;
    }
    while(B.back()==0&&B.size()>1)B.pop_back();
}
int main(){
    cin >> a >> x;
    for(int i = a.size()-1 ; i >= 0 ; i --)A.push_back(a[i]-'0');
    mul(A,x);
    for(int i = B.size()-1 ; i >= 0 ; i --)printf("%d",B[i]);
    return 0;
}


活动打卡代码 AcWing 792. 高精度减法

May_wind
2个月前
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>

using namespace std;

vector<int>a,b,c;
string A,B;
bool cmp(vector<int>a,vector<int>b){
    if(a.size() != b.size())return a.size()>b.size();
    for(int i = a.size()-1 ; i >= 0 ; i --)
        if(a[i] != b[i])return a[i] > b[i];
    return true;
}
void sub(vector<int>x,vector<int>y){
    int t = 0;
    for(int i = 0 ; i < x.size() || t ; i ++){
        t = x[i]-t;
        if(i < y.size())t -= y[i];
        c.push_back((t+10)%10);
        t = t >= 0?0:1;
    }
    while(c.back()==0&&c.size()>1)c.pop_back();
}
int main(){
    cin >> A >> B;
    for(int i = A.size()-1 ; i >= 0 ; i --)a.push_back(A[i]-'0');
    for(int i = B.size()-1 ; i >= 0 ; i --)b.push_back(B[i]-'0');
    if(cmp(a,b)){
        sub(a,b);
        for(int i = c.size()-1 ; i >= 0 ; i --)printf("%d",c[i]);
    }
    else {
        sub(b,a);printf("-");
        for(int i = c.size()-1 ; i >= 0 ; i --)printf("%d",c[i]);
    }
    return 0;
}


活动打卡代码 AcWing 282. 石子合并

May_wind
2个月前
#include<iostream>
#include<cstdio>

using namespace std;

int n,a[310],s[310],f[310][310];
int main(){
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i ++){
        scanf("%d",&a[i]);
        s[i] = s[i-1]+a[i];
    }
    for(int len = 2 ; len <= n ; len ++){
        for(int i = 1 ; i+len-1 <= n ; i ++){
            int j = i+len-1;
            f[i][j] = 0x7fffffff;
            for(int k = i ; k < j ; k ++)
                f[i][j] = min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
        }
    }
    cout << f[1][n];
    return 0;
}



May_wind
2个月前

大佬们,求助一道题
题目链接 能量项链

错误的代码:

#include<iostream>
#include<cstdio>

using namespace std;

int n,a[210],f[210][210],ans=-10;
int main(){
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i ++){
        scanf("%d",&a[i]);
        a[i+n] = a[i];
    }
    for(int len = 1 ; len <= n ; len ++){
        for(int i = 1 ; i + len -1 <= 2*n ; i ++){
            int j = i + len -1;
            for(int k = i ; k < j ; k ++){
                f[i][j] = max(f[i][j],f[i][k]+f[k+1][j]+a[i]*a[k+1]*a[j]);
            }
        }
    }
    for(int i = 1 ; i <= n ; i ++){
        ans = max(ans,f[i][i+n-1]);
    }
    cout << ans;
    return 0;
}
}

某个错误的测试点:

7
23 17 212 113 71 301 33 
程序:25115922
正确答案:31182687



May_wind
2个月前

$O(n)$

#include<iostream>
#include<cstdio>

using namespace std;

int n,m,g[510][510],dis[510],a,b,c,t;
bool vis[510];
int main(){
    scanf("%d%d",&n,&m);
    for(int i = 1 ; i < n ; i ++)
        for(int j = 1 ; j <= n ; j ++)
            g[i][j] = 0x3f3f3f3f;
    for(int i = 1 ; i <= m ; i ++){
        scanf("%d%d%d",&a,&b,&c);
        g[a][b] = min(g[a][b],c);
    }
    for(int i = 1 ; i <= n ; i ++)dis[i] = 0x3f3f3f3f;
    dis[1] = 0;
    for(int i = 1 ; i <= n ; i ++){
        t = -1;
        for(int j = 1 ; j <= n ; j ++)
            if(!vis[j]&&(t==-1||dis[j]<dis[t]))t=j;
        vis[t] = true;
        for(int j = 1 ; j <= n ; j ++){
            dis[j] = min(dis[j],dis[t]+g[t][j]);
        }
    }
    if(dis[n]==0x3f3f3f3f)dis[n] = -1;
    cout << dis[n];
    return 0;
}



May_wind
2个月前

$O(n)$

#include<iostream>
#include<cstdio>

using namespace std;

int n,arr[1010],f[1010];
int main(){
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i ++)
        scanf("%d",&arr[i]);
    for(int i = 1 ; i <= n ; i ++){
        f[i] = 1;
        for(int j = 1 ; j <= i ; j ++){
            if(arr[j] < arr[i] && f[i] < f[j]+1)
                f[i] = f[j]+1;
        }
    }
    int ans = -10;
    for(int i = 1; i <= n ; i ++)ans = ans>f[i]?ans:f[i];
    cout << ans;
    return 0;
}


活动打卡代码 AcWing 791. 高精度加法

May_wind
5个月前
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>

using namespace std;

vector<int>A,B,C;
string a,b;
void add(){
    int t = 0;
    for(int i = 0 ; i < A.size() || i < B.size() ; i ++){
        if(i < A.size())t += A[i];
        if(i < B.size())t += B[i];
        C.push_back(t%10);
        t /= 10;
    }
    if(t)C.push_back(t);
}
int main(){
    cin >> a >> b;
    for(int i = a.size()-1 ; i >= 0 ; i --)A.push_back(a[i]-'0');
    for(int i = b.size()-1 ; i >= 0 ; i --)B.push_back(b[i]-'0');
    add();
    for(int i = C.size()-1 ; i >= 0 ; i --)printf("%d",C[i]);
    return 0;
}



May_wind
5个月前
#include<iostream>
#include<cstdio>

using namespace std;

int n,m,k,a[100010],b[100010];
int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i = 1 ; i <= n ; i ++)scanf("%d",&a[i]);
    for(int i = 1 ; i <= m ; i ++)scanf("%d",&b[i]);
    for(int i = 1,j = m ; i <= n ; i ++){
        while(a[i]+b[j]>k)j--;
        if(a[i]+b[j]==k){
            printf("%d %d",i-1,j-1);break;
        }
    }
    return 0;
}