zoukankan      html  css  js  c++  java
  • 2019CSP-J第二轮 B题C题

    B.简单模拟

    /* 寻找每一张公交票可用的最早的地铁优惠票,使用过之后一定要销毁*/

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 using namespace std;
     5 int n;
     6 int price[100005];
     7 int times[100005];
     8 int vis[100005];
     9 int ans=0;
    10 int cnt=0;
    11 int check=0;
    12 int main()
    13 {
    14     scanf("%d",&n);
    15     for(int i=1;i<=n;i++){
    16         int a,b,c;
    17         scanf("%d%d%d",&a,&b,&c);
    18         if(a==0){
    19             ans+=b;
    20             price[cnt]=b;
    21             times[cnt]=c;
    22             cnt++;
    23         }else{
    24             int flag=0;
    25             int buge=check;
    26             while(buge<cnt){
    27                 if(c-times[buge]<=45){
    28                     if(price[buge]>=b){
    29                         flag=1;
    30                         price[buge]=-1000000001;
    31                         break;
    32                     }
    33                 }
    34                 else
    35                     check++;
    36                 buge++;
    37             }
    38             if(flag==0){
    39                 ans+=b;
    40             }
    41         }
    42     }
    43     printf("%d
    ",ans);
    44     return 0;
    45 }

    C.完全背包

    /*需要进行模型转换 背包容量为金币数量 物品的体积为纪念品的单价 物品的价值为今天买入明天卖出的收益*/

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 using namespace std;
     5 int t,n,m;
     6 int a[105][105];
     7 int cha[105][105];
     8 int dp[10005];
     9 int main(){
    10     scanf("%d %d %d",&t,&n,&m);
    11     for (int i=1; i<=t; i++) {
    12         for(int j=1;j<=n;j++){
    13             scanf("%d",&a[i][j]);
    14         }
    15     }
    16     for(int i=1;i<=t;i++){
    17         for(int j=1;j<=n;j++){
    18             cha[i][j]=max(0,a[i+1][j]-a[i][j]);
    19         }
    20     }
    21     for(int i=1;i<=t;i++){
    22         for(int s=0;s<=m;s++){
    23             dp[s]=0;
    24         }
    25         for(int j=1;j<=n;j++){
    26             for(int s=a[i][j];s<=m;s++){
    27                 dp[s]=max(dp[s],dp[s-a[i][j]]+cha[i][j]);
    28             }
    29         }
    30         m=m+dp[m];
    31     }
    32     printf("%d
    ",m);
    33     return  0;
    34 }
  • 相关阅读:
    Oracle9使用oradata恢复数据库
    我该怎么安排下属的工作项目经理如何分配任务
    如果说中国的程序员技术偏低,原因可能在这里
    项目经理问:为什么总是只有我在加班 – 挂包袱现象
    【转】面试真经
    [JAVA]PING和TELNET用法介绍
    Hello World 你懂的
    线程间操作控件
    获取客户端相关信息
    winfrom 特效 [转载]
  • 原文地址:https://www.cnblogs.com/hsd-/p/11885942.html
Copyright © 2011-2022 走看看