比赛的过程中,费尽脑力,A出三道水题,实在是感慨万千:
Time Limit:1s Memory Limit:128MByte
Submissions:332Solved:114
给你一个01串,我们定义这个串的咸鱼值,是最长的全1串。现在你最多可以使用K次咸鱼魔法,每次魔法,你可以使得一个位置翻转(0变成1,1变成0)。问你这个串的咸鱼值最多是多少。
#include <iostream>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#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<<"&&&&"<<dp[i]<<endl;
//continue;
}else{
if(k>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<<dp[i]<<"*"<<maxx<<endl;
if(dp[i]>maxx) maxx=dp[i];
}
cout<<maxx<<endl;
}
int main(){
while(~scanf("%d %d",&n,&k)){
memset(dp,0,sizeof(dp));
memset(p,0,sizeof(p));
for(int i=1;i<=n;i++){
scanf("%d",&str[i]);
}
//scanf("%s",str+1);
solve();
}
return 0;
}
//
/*
10 2
1001010101
*/
Time Limit:3s Memory Limit:256MByte
Submissions:166Solved:66
你现在在咸鱼商店,你有M元钱。咸鱼商店有N个物品,每个物品有两个属性,一个是他的价格S[i],另外一个是他的价值V[i]。现在你想买一些物品,使得这些物品的价值和大于等于K,并且使得其中价值最低的商品的价值尽量高。请你输出这个最大价值。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define siz 1005
using namespace std;
int n,m,k;
struct node{
int s,v;
bool operator <(const node &a)const{
return v<a.v;
}
}p[siz];
int dp[siz][siz];
void solve(){
sort(p+1,p+n+1);
int ans=0,ant=0;
int is=-1;
for(int i=n;i>0;i--){
//cout<<p[i].s<<" "<<p[i].v<<endl;
if(ans+p[i].s<=m){
if(ant+p[i].v>=k){
is=p[i].v;
break;
}else{
ans=ans+p[i].s;
ant=ant+p[i].v;
}
}
}
cout<<is<<endl;
}
int main()
{
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%d %d",&p[i].s,&p[i].v);
}
solve();
return 0;
}
Time Limit:1s Memory Limit:128MByte
Submissions:418Solved:163
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 ! "
你正在做英语阅读,可哪知这是一篇咸鱼文章,整个文章的所有单词都是翻转的,你很慌。
不过你是咸鱼程序员,你可以写代码将这篇文章翻转回来,那么翻转回来吧。
#include <iostream>
#include <stdio.h>
#include <string.h>
#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<<se[strlen(se)]<<endl;
int r=0;
k=0;
while(r<=strlen(se)){
c=se[r];
//if(c==se[strlen(se)])
//cout<<"%"<<endl;
if(c==' '||c==se[strlen(se)]){
//str[i++]=' ';
for(int j=k-1;j>=0;j--){
str[i++]=s[j];
}
k=0;
s[0]=' ';
if(c==se[strlen(se)])
//cout<<c<<endl;
str[i++]='\n';
else str[i++]=' ';
}else{
s[k++]=c;
}
++r;
}
if(k!=0){
for(int j=k-1;j>=0;j--){
str[i++]=s[j];
}
str[i++]=c;
}
}
for(int j=0;j<i;j++){
putchar(str[j]);
}
return 0;
}
最后就是H题我的线段树写挂了,一直没A,E题最短路,最小费用流都试了,就是没试最小生成树,。。。题解生成树+bfs?,J题完全懵逼,还能假设边?还能正玄定理,余弦定理?表示完全没往这方面想。。。A题看了一波就放弃了。最后。。。这几天貌似做题都挺顺的,至少不像以前那样持续懵逼了。。


被折叠的 条评论
为什么被折叠?



