zoukankan      html  css  js  c++  java
  • 【比赛】 AtCoder Beginner Contest 167

    题意/题解

    A Registration

    • 题意:输入一个字符串 (s) 和一个字符串 (t),让你判断 (t) 是不是由 (s) 在末尾加一个小写字母的得到的。
    • 题解:c++ 的 (string) 可以直接加。

    B Easy Linear Programming

    • 题意:有 (a)(1)(b)(0)(c)(-1)。让你从中选 (k) 个使得最后的和最大。
    • 题解:先选 (1) 再选 (0) 最后选 (-1)

    C Skill Up

    • 题意:有 (m) 个算法,(n) 本书,你对 (m) 个算法的理解程度一开始为 (0),让你从 (n) 本书中选几本书使得最后你对 (m) 个算法的理解程度都大于等于 (x),如果不可能输出 (-1)
    • 题解:爆搜 (O(2^n))

    D Teleporter

    • 题意:有 (n) 个城镇,每个城镇都有一个传送门去往一个城镇,你一开始在 (1) 号城镇,问你经过 (k) 次传送后在哪?
    • 题解:当 (k) 足够大时一定存在一个环,找到这个环,让 (k) 模环的长度再暴力传送即可。

    E Colorful Blocks

    • 题意:咕咕咕
    • 题解:咕咕咕

    F Bracket Sequencing

    • 题意:咕咕咕
    • 题解:咕咕咕

    代码

    A Registration

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<iostream>
    #include<algorithm>
    
    inline void read(int &T) {
    	int x=0;bool f=0;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    	T=f?-x:x;
    }
    
    std::string a,b;
    
    int main() {
    	std::cin>>a>>b;
    	int len2=b.length();
    	std::string change=a+b[len2-1];
    	if(change!=b) puts("No");
    	else puts("Yes");
    	return 0;
    }
    

    B Easy Linear Programming

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<iostream>
    #include<algorithm>
    
    inline void read(int &T) {
    	int x=0;bool f=0;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    	T=f?-x:x;
    }
    
    int a,b,c,k;
    long long ans=0;
    
    int min(int x,int y) {return x<y?x:y;}
    
    int main() {
    	read(a),read(b),read(c),read(k);
    	ans+=min(a,k);
    	k-=a,k-=b;
    	if(k<=0) {
    		std::cout<<ans<<'
    ';
    		return 0;
    	}
    	ans-=min(c,k);
    	std::cout<<ans<<'
    ';
    	return 0;
    }
    

    C Skill Up

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<iostream>
    #include<algorithm>
    
    inline void read(int &T) {
    	int x=0;bool f=0;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    	T=f?-x:x;
    }
    
    int n,m,x,cnt,sd[15];
    int c[15],a[15][15];
    int now[15];
    long long ans=1e17;
    
    void count() {
    	long long tot=0;
    	memset(now,0,sizeof now);
    	for(int i=1;i<=cnt;++i) {
    		tot+=c[sd[i]];
    		for(int j=1;j<=m;++j) {
    			now[j]+=a[sd[i]][j];
    		}
    	}
    	for(int i=1;i<=m;++i) {
    		if(now[i]<x) return;
    	}
    	if(tot<ans) ans=tot;
    }
    
    void dfs(int step) {
    	if(step>n) {
    		count();
    		return;
    	}
    	for(int i=0;i<=1;++i) {
    		if(i==1) {
    			sd[++cnt]=step;
    			dfs(step+1);
    			--cnt;
    		}else dfs(step+1);
    	}
    }
    
    int main() {
    	read(n),read(m),read(x);
    	for(int i=1;i<=n;++i) {
    		read(c[i]);
    		for(int j=1;j<=m;++j) {
    			read(a[i][j]);
    		}
    	}
    	dfs(1);
    	if(ans==1e17) puts("-1");
    	else std::cout<<ans<<'
    ';
    	return 0;
    }
    

    D Teleporter

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<iostream>
    #include<algorithm>
    #define MAXN 200001
    #define int long long
    
    inline void read(int &T) {
    	int x=0;bool f=0;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    	T=f?-x:x;
    }
    
    int n,a[MAXN],last[MAXN],k;
    
    signed main() {
    	read(n),read(k);
    	for(int i=1;i<=n;++i) read(a[i]);
    	last[1]=1;int now=1;
    	while(k) {
    		if(last[a[now]]) {
    			int times=last[now]+1-last[a[now]];
    			k%=times;
    			if(k==0) break;
    			--k;
    			now=a[now];
    			while(k!=0) {
    				now=a[now];
    				--k;
    			}
    		}
    		if(!k) break;
    		last[a[now]]=last[now]+1;
    		now=a[now];
    		--k;
    	}
    	printf("%lld
    ",now);
    	return 0;
    }
    

    反思:

    • 太菜了。
  • 相关阅读:
    linux command line send email
    js的小随笔
    JavaScript的严格模式
    nodejs学习笔记<六>文件处理
    nodejs学习笔记<五>npm使用
    nodejs学习笔记<四>处理请求参数
    nodejs学习笔记<三>关于路由(url)
    nodejs学习笔记<一>安装及环境搭建
    转:HTTP 301 跳转和302跳转的区别
    前端代码新写法——Zen Coding
  • 原文地址:https://www.cnblogs.com/poi-bolg-poi/p/12865367.html
Copyright © 2011-2022 走看看