玲珑杯#15之三道水题

比赛的过程中,费尽脑力,A出三道水题,实在是感慨万千:

1124 - 咸鱼魔法记

Time Limit:1s Memory Limit:128MByte

Submissions:332Solved:114

DESCRIPTION

给你一个01串,我们定义这个串的咸鱼值,是最长的全1串。现在你最多可以使用K次咸鱼魔法,每次魔法,你可以使得一个位置翻转(0变成1,1变成0)。问你这个串的咸鱼值最多是多少。

INPUT
第一行两个整数N,K。表示串的长度和可以施展咸鱼魔法的次数。(N,K<=300000)第二行N个01整数。
OUTPUT
输出答案。
SAMPLE INPUT
10 2
1 0 0 1 0 1 0 1 0 1
SAMPLE OUTPUT
5
说好的是字串,结果输入的是数组?我还以为是字符串。思路:枚举区间,这个区间内包含k个0,区间右边发现一个0之后,区间左边第一个0要去掉,然后动态更新最大值就好

#include 
#include 
#include 
#include 
#include 
#define MAXX 0x3f3f3f3f
#define siz 500005
#define LL long long
using namespace std;
char str[siz];
int n,k;
int dp[siz];
int p[siz];
void solve(){
    int s=-1,current=0;
    int maxx=0;
    int zx=0;
    for(int i=1;i<=n;i++){
        if(str[i]==1){

            dp[i]=dp[i-1]+1;
            //cout<<1<<"&&&&"<0){
                --k;
                dp[i]=dp[i-1]+1;
                p[zx]=i;
                if(s==-1) s=zx;
                ++zx;
            }else{
                if(s==-1) dp[i]=0;
                else{
                dp[i]=i-p[s];
                p[zx]=i;
                ++zx;
                ++s;
                }

            }
        }
        //cout<maxx) maxx=dp[i];
    }
    cout<
1125 - 咸鱼商店

Time Limit:3s Memory Limit:256MByte

Submissions:166Solved:66

DESCRIPTION

你现在在咸鱼商店,你有M元钱。咸鱼商店有N个物品,每个物品有两个属性,一个是他的价格S[i],另外一个是他的价值V[i]。现在你想买一些物品,使得这些物品的价值和大于等于K,并且使得其中价值最低的商品的价值尽量高。请你输出这个最大价值。

INPUT
第一行三个整数N,M,K。接下来N行,每行两个整数S和V,分别表示价格和价值。满足:1 <= N, M, S <= 10^3, 0 <= V, K <= 10^6
OUTPUT
输出价值最低的商品能够达到的最大价值。如果无解,输出-1
SAMPLE INPUT
3 10 1
1 2
10 1
5 5
SAMPLE OUTPUT
5
最开始我还以为是01背包,一波模板打下来,发现是贪心??果断贪了一波
#include 
#include 
#include 
#include 
#define siz 1005

using namespace std;
int n,m,k;
struct node{
    int s,v;
    bool operator <(const node &a)const{
        return v0;i--){
        //cout<=k){
               is=p[i].v;
               break;
            }else{
                ans=ans+p[i].s;
                ant=ant+p[i].v;
            }

       }
    }
    cout<
1127 - 咸鱼文章

Time Limit:1s Memory Limit:128MByte

Submissions:418Solved:163

DESCRIPTION

elttiL moT nwod eht teerts sllac ruo god " ehT peek god " . piZ si a peehs god . tuB nehw moT seirt ot yas " peeS " , ti semoc tuo " peek " . dnA ni a yaw moT si thgir . piZ si syawla gnignirb sgniht oh rof su ot peek ! ll'I llet uoy tuoba emos fo meht .
s'piZ tsrif tneserp saw a eohs . tI saw edam fo neerg klis .
eW t'ndid wonk woh piZ dnuof eht eohs . tuB retfa a tnemom yraM , ym gib retsis , dlot em eht eohs dah a egnarts llems . I deddon dna dleh ym eson . " tahW od uoy kniht ti si ? "
" tI sllems ekil gnihtemos rof gninaelc . I kniht enoemos deirt ot naelc a tops ffo eht eohs . nehT eh tup ti ta eht rood ot yrd . "
" gnolA emac piZ . dnA eyb-doog eohs ! " I dias . " eW dluohs ekat ti kcab . "
" eW t'nac " . dias ym rettsis .
" ebyaM elttil moT si thgir , " yraM dias . " ebyaM piZ si a peek god ! "

你正在做英语阅读,可哪知这是一篇咸鱼文章,整个文章的所有单词都是翻转的,你很慌。

不过你是咸鱼程序员,你可以写代码将这篇文章翻转回来,那么翻转回来吧。

INPUT
输入一篇英文文章。输入数据中只包含空格、换行符和小写大写字母。满足总字数小于等于100000
OUTPUT
你应该把这个文章的所有单词都翻转回来,输出即可。
SAMPLE INPUT
AAA BBB
AB AB
SAMPLE OUTPUT
AAA BBB
BA BA
文章结束应该是以ctrl+z结束,所以只要gets输入就好,主要是'\n'坑了我一波,只好暴力c==se[strlen(se)]判断,哭死我也

#include 
#include 
#include 
#define siz 100100
using namespace std;
char str[siz],s[siz],se[siz];
int main()
{
    char c;
    int i=0;
    int k=0;
    //s[0]=' ';
    while(gets(se)){
            //cout<=0;j--){
                    str[i++]=s[j];
                }
            k=0;
            s[0]=' ';
            if(c==se[strlen(se)])
            //cout<=0;j--){
                    str[i++]=s[j];
                }
        str[i++]=c;
    }
    }

    for(int j=0;j

最后就是H题我的线段树写挂了,一直没A,E题最短路,最小费用流都试了,就是没试最小生成树,。。。题解生成树+bfs?,J题完全懵逼,还能假设边?还能正玄定理,余弦定理?表示完全没往这方面想。。。A题看了一波就放弃了。最后。。。这几天貌似做题都挺顺的,至少不像以前那样持续懵逼了。。





你可能感兴趣的:(个人感想,基础算法)