AtCoder Beginner Contest 167

abc过的挺顺利的到D就卡了,又wa又T

A.Registration

题目大意

题目意思大概就是给你字符串S和T,确保T的长度比S多1,求S是否是T的前缀

思路

暴力模拟

代码

/*********************
*@Author:   CKang    *
*@Language: C++11    *
*********************/
#include<bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
//#define DEBUG
#define RI register int
#define endl "\n"

using namespace std;

typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3fffffff;
const ll LINF = 0x3fffffffffffffff;

inline ll read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

void solve(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            puts("No");
            return ;
        }
    }
    puts("Yes");
    return ;
}

int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout)
#endif
    //cout.tie(0);
    //for(ll t=read();t;t--)
        solve();
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}

B.Easy Linear Programming

题目大意

给你a个1,b个0,c个-1,共a+b+c个数字以及一个整数k,求从这些数字中选k个求和,要求和最大

思路

先拿1再是0再是-1

代码

/*********************
*@Author:   CKang    *
*@Language: C++11    *
*********************/
#include<bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
//#define DEBUG
#define RI register int
#define endl "\n"

using namespace std;

typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3fffffff;
const ll LINF = 0x3fffffffffffffff;

inline ll read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

void solve(){
    ll a=read(),b=read(),c=read(),k=read(),sum=0;
    if(k>a){
        sum+=a;
        k-=a;
        if(k>b){
            k-=b;
            if(k>c){
                return ;
            }
            else {
                printf("%d\n",sum-k);
            }
        }
        else {
            printf("%d\n",sum);
        }
    }
    else {
        printf("%d\n",k);
    }
    return ;
}

int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout)
#endif
    //cout.tie(0);
    //for(ll t=read();t;t--)
        solve();
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}

C.Skill Up

题目大意

对于n本书,每一本书都有价值c,以及对m个不同能力的不同的增益,求各个增益均大于x时所挑选书的c之和最小值

思路

每本书都是选和不选,数据小直接dfs了,数据大一点就要dp了(但是不会)

代码

//********************
//*@Author:  ChenShou*
//*@Language:C++11   *
//********************

#include<bits/stdc++.h>

//#pragma comment ( linker ," /STACK:102400000 , 102400000 " )
//#define DEBUG
#define RI register int
#define endl "\n"

using namespace std ;

typedef long long ll ;
// typedef __int128 lll ;
const int MOD = 1e9 + 7 ;
const double PI = acos(-1.0) ;
const double EXP = 1E-9 ;
const int INF = 0x3f3f3f3f;

inline ll read(){
    long long x = 0 , f = 1 ;
    char ch = getchar() ;
    while(ch<'0'||ch>'9'){
        if(ch == '-') f = -1 ;
        ch = getchar();
    }
    while(ch >='0' && ch <= '9' ){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x*f ;
}

struct mas{
    int c;
    int a[15];
};

mas sum={0};
ll N,M,X,min_c=INF;
mas mass[15];

void dfs(int n,mas tmp){
    if(n==N)return ;
    bool flag=true;

    dfs(n+1,tmp);

    tmp.c+=mass[n].c;
    for(int i=0;i<M;i++){
        tmp.a[i]+=mass[n].a[i];
        if(tmp.a[i]<X){
            flag=false;
        }
    }
    if(flag&&tmp.c<min_c)min_c=tmp.c;
    dfs(n+1,tmp);


    return ;
}

void solve(){
	N=read(),M=read(),X=read();
	for(int i=0;i<N;i++){
        mass[i].c=read();
        for(int j=0;j<M;j++){
            mass[i].a[j]=read();
        }
	}
	dfs(0,sum);
	if(min_c!=INF)cout<<min_c<<endl;
	else cout<<-1<<endl;
	return ;
}

int main(){
#ifdef DEBUG
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
#endif
//	for(ll T=read();T;T--)
		solve();
#ifdef DEBUG
    printf("\nHellow , Mr.ChenShou\n");
    printf("\t Time cost : %lf s \n",(double)clock()/CLOCKS_PER_SEC);
#endif
    return 0;
}

D.Teleporter

题目大意

题目意思大概就是每一个城市可以传送到另一个城市,从1号城市开始传送k次到那个城市

思路

对于次数多的时候必有环,直接标记走过的点走过几次,只走过一次的点就是进入环之前的铺垫,走过两次的就是环上的点了,记录环的长度后求余即可。

代码

/*********************
*@Author:   CKang    *
*@Language: C++11    *
*********************/
#include<bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
//#define DEBUG
#define RI register int
#define endl "\n"

using namespace std;

typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3fffffff;
const ll LINF = 0x3fffffffffffffff;

inline ll read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int nums[200005]={0};int mp[200005]={0};

void solve(){
    ll n=read(),k=read(),city=1,cir=0,fir;
    for(int i=1;i<=n;i++)nums[i]=read();
    for(;;){
        mp[city]++;
        if(mp[city]==3){
            fir=city;
            break;
        }
        if(mp[city]==2){
            cir++;
        }
        if(mp[city]==1){
            k--;
            if(k==0){          //就是这里忘记判断了,又T又wa
                cout<<nums[city]<<endl;
                return ;
            }
        }
        city=nums[city];
    }
    k=k%cir;
    while(k){
        fir=nums[fir];
        k--;
    }
    cout<<fir<<endl;
    return ;
}

int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout)
#endif
    //cout.tie(0);
    //for(ll t=read();t;t--)
        solve();
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}
posted @ 2020-05-10 23:26  ChenShou  阅读(307)  评论(0编辑  收藏  举报