zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest-060

    A - Shiritori

    Problem Statement

    You are given three strings A, B and C. Check whether they form a word chain.

    More formally, determine whether both of the following are true:

    The last character in A and the initial character in B are the same.
    The last character in B and the initial character in C are the same.
    If both are true, print YES. Otherwise, print NO.

    Constraints
    A, B and C are all composed of lowercase English letters (a - z).
    1≤|A|,|B|,|C|≤10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

    题目大意

    给三个字符串,ABC是否首位相接

    代码

    #include <bits/stdc++.h>
    using namespace std;
     
    string a,b,c;
     
    int main() 
    {
    	cin>>a>>b>>c;
    	if (a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) cout<<"YES"<<endl;
    	else cout<<"NO"<<endl;
    }
    

    B - Choose Integers

    Problem Statement

    We ask you to select some number of positive integers, and calculate the sum of them.

    It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.

    Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.

    If the objective is achievable, print YES. Otherwise, print NO.

    题目大意

    (k*a)%b是否有c这个余数

    代码

    #include <bits/stdc++.h>
    using namespace std;
     
    int a,b,c;
    int f[100];
     
    int main() 
    {
    	cin>>a>>b>>c;
    	int j=a%b;
    	while (1)
    	{
    		if (j==c)
    		{
    			cout<<"YES"<<endl;
    			return 0;
    		}
    		if (f[j])
    		{
    			cout<<"NO"<<endl;
    			return 0;
    		}else f[j]=1;
    		j=(j+a)%b;
    	}
    }
    

    C - Sentou

    Problem Statement

    In a public bath, there is a shower which emits water for T seconds when the switch is pushed.

    If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds.

    N people will push the switch while passing by the shower. The i-th person will push the switch ti seconds after the first person pushes it.

    How long will the shower emit water in total?

    题目大意

    给出一堆线段,问覆盖的长度是多少,升序O(n)扫一遍就好了

    代码

    #include <bits/stdc++.h>
    using namespace std;
     
    int n,t; 
    int f[200010];
    long long ans;
     
    int main() 
    {
    	cin>>n>>t;
    	for (int i=1;i<=n;i++) scanf("%d",&f[i]);
    	for (int i=1;i<n;i++) ans+=min(f[i+1]-f[i],t);
    	cout<<ans+t<<endl;
    }
    

    D - Simple Knapsack

    Problem Statement

    You have N items and a bag of strength W. The i-th item has a weight of wi and a value of vi.

    You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.

    Your objective is to maximize the total value of the selected items.

    Constraints
    1≤N≤100
    1≤W≤109
    1≤wi≤109
    For each i=2,3,…,N, w1≤wi≤w1+3.
    1≤vi≤107
    W, each wi and vi are integers.

    题目大意

    装包问题,发现有w1≤wi≤w1+3这个条件,就可以压缩背包大小
    f[i][j]表示装了i个物品,重量为w1*i+j;

    代码

    #include <bits/stdc++.h>
    using namespace std;
     
    int n;
    int w;
    long long a[110];//w
    long long b[110]; //v
    long long f[110][330];
    const int INF=(0x7fffffff)/2;
    long long ans;
     
    int main() 
    {
    	cin>>n>>w;
    	for (int i=1;i<=n;i++) cin>>a[i]>>b[i];
    	for (int i=0;i<110;i++) 
    		for (int o=0;o<330;o++) f[i][o]=-INF;
    	f[0][0]=0;
    	for (int i=1;i<=n;i++)
    		for (int o=i-1;o>=0;o--) 
    			for (int j=0;j<=3*o;j++) 
    				if (f[o][j]!=INF) f[o+1][j+(a[i]-a[1])]=max(f[o+1][j+(a[i]-a[1])],f[o][j]+b[i]);
    	
    	for (int i=1;i<=n;i++) 
    		for (int o=0;o<330;o++) if (i*a[1]+o<=w && f[i][o]!=INF) ans=max(ans,f[i][o]);
    		
    	cout<<ans<<endl;
    }
    

    赛后反思

    很简单的题目,难点在于英文阅读qwq。

  • 相关阅读:
    python IDE安装-mac
    tokudb引擎安装-2
    MariaDB10.2.X-新特性2-支持check约束and with as
    MariaDB10.2.X-新特性1-支持分析函数
    MySQL5.7表空间加密
    MySQL 5.7 SYS scheme解析
    tcpdump抓SQL
    pt-online-schema-change
    查看锁信息
    onlineDDL测试
  • 原文地址:https://www.cnblogs.com/EDGsheryl/p/6829484.html
Copyright © 2011-2022 走看看