2019.9.15 CSP-S模拟赛

前言

一大波原题来袭!!!(大雾
考得不太好吧0+100+0=100(T3数据出锅了

T1-P5424 [USACO19OPEN]Snakes

题意

有$n$组蛇,每一组蛇有$a_i$条蛇,你有一张网,需要将蛇全部抓住。一次抓一组蛇,因此每次要使网比当前组的蛇的数量大。你可以改变$k$次网的大小,问抓住所有蛇的总浪费空间的最小值?
对于$100 \% $的数据$1\leq n \leq 400,0\leq a_i \leq 10^6$

思路

考虑$DP$,设$f[i][j]$表示前$i$组蛇,改变了$j$次网的大小的最小浪费空间值。
那么$f[i][j]=min(f[i][j],f[k][j-1]+(i-k)*Max[k+1][i]-(sum[i]-sum[k]))$
其中$sum$表示前缀和,$Max$表示区间最大值。
所以只要先维护前缀和与区间最大值即可。

Code

#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;

#define re register
//#define int int 

class Quick_Input_Output{
    private:
        static const int S=1<<21;
        #define tc() (A==B&&(B=(A=Rd)+fread(Rd,1,S,stdin),A==B)?EOF:*A++)
        char Rd[S],*A,*B;
        #define pc putchar
    public:
        #undef gc
        #define gc getchar 
        inline int read(){
            int res=0,f=1;char ch=gc();
            while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=gc();}
            while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=gc();
            return res*f;
        }
        inline void write(int x){
            if(x<0) pc('-'),x=-x;
            if(x<10) pc(x+'0');
            else write(x/10),pc(x%10+'0');
        }
        #undef gc
        #undef pc
}I;
#define File freopen("pa.in","r",stdin);freopen("pa.out","w",stdout);
int n,K,a[410],f[410][410],sum[410],Max[410][410],ans=2e9;
int main(){
    File
    n=I.read();K=I.read();K++;
    for(int i=1;i<=n;i++) a[i]=I.read();
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++){
            if(i==j) Max[i][j]=a[i];
            else Max[i][j]=max(Max[i][j-1],a[j]);
        }
    memset(f,63,sizeof(f));f[0][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=K;j++){
            for(int k=0;k<i;k++){
                f[i][j]=min(f[i][j],f[k][j-1]+(i-k)*Max[k+1][i]-(sum[i]-sum[k]));
            }
        }
    }
    for(int i=1;i<=K;i++) ans=min(ans,f[n][i]);
    I.write(ans);putchar('\n');
}

T2-P5425 [USACO19OPEN]I Would Walk 500 Miles

题意

(你自己点链接看,(╯▔皿▔)╯

思路

乱搞贪心,比赛时候竟然过了?( ̄▽ ̄)”
贪心将其分组成一下形式:$(1),(2),(3),(4),…,(P),(P+1,P+2,P+3,…,N-1,N)$
然后跑一遍求值。

Code

#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;

#define re register
#define int long long 

class Quick_Input_Output{
    private:
        static const int S=1<<21;
        #define tc() (A==B&&(B=(A=Rd)+fread(Rd,1,S,stdin),A==B)?EOF:*A++)
        char Rd[S],*A,*B;
        #define pc putchar
    public:
        #undef gc
        #define gc getchar 
        inline int read(){
            int res=0,f=1;char ch=gc();
            while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=gc();}
            while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=gc();
            return res*f;
        }
        inline void write(int x){
            if(x<0) pc('-'),x=-x;
            if(x<10) pc(x+'0');
            else write(x/10),pc(x%10+'0');
        }
        #undef gc
        #undef pc
}I;
#define File freopen("pb.in","r",stdin);freopen("pb.out","w",stdout);
int n,k,ans=2e18;
inline int dis(int x,int y){
    return (2019201913*x%2019201997+2019201949*y%2019201997)%2019201997;
}
signed main(){
    File
    n=I.read();k=I.read();
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(i>=k&&j>=k) ;
            else ans=min(ans,dis(i,j)); 
        }
    }
    I.write(ans);putchar('\n');
    return 0;
}

T3-P5423 [USACO19OPEN]Valleys

题意

(还是自己看┗|`O′|┛

思路

(留个坑,似乎是个定理题
粘个题解慢慢看:


题解出自这里

评论

  1. Orz
    2年前
    2019-9-18 18:07:36

    Orz

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇