• hdu1300Pearls


    我也不知道我的代码错在哪里

    #include "iostream"
    using namespace std;
    struct{
      int n,p;
    }thing[10000];
    int main(){
      int ncase,n,i,j,num,total;
      cin>>ncase;
      while(ncase--){
        cin>>n;
        for(i=1;i<=n;i++){cin>>thing[i].n>>thing[i].p;}
    
        num=0;total=0;
        for(i=1;i<=n;i++){
          if((thing[i].n+10)*thing[i].p>thing[i].n*thing[i+1].p&&i!=n){
            num+=thing[i].n;
          }
          else {
            num+=thing[i].n;
            total+=(num+10)*thing[i].p;
            //cout<<i<<' ';
            num=0;
          }
        }
        //cout<<endl;
        cout<<total<<endl;
      }
    }

    网上的代码

    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    using namespace std;
    int t,n,a[105],p[105],ans[105],sum[105];
    
    int main() {
        int i,j,k,l;
        scanf("%d", &t);
        while(t--) {
            memset(ans, 0,sizeof(ans));
            sum[0]=0;
            scanf("%d", &n);
            for (j=1; j<=n; j++) {
                scanf("%d%d", &a[j], &p[j]);
                sum[j] = sum[j-1] + a[j];
                ans[j] = (sum[j]+10) * p[j];
            }
            for (j=1; j<=n; j++) {
                for (k=1; k<=j; k++) {
                    ans[j] = min(ans[j],(sum[j]-sum[k] +10) * p[j]+ans[k]);
                }
            }
            printf("%d
    ", ans[n]);
        }
    }
  • 相关阅读:
    大数据
    入门
    bootstrap
    django 实现
    django
    爬虫
    汇编指令
    JavaScript
    那些年踩过的坑
    实现网页代码
  • 原文地址:https://www.cnblogs.com/dowson/p/3290814.html
Copyright © 2020-2023  润新知