AtCoder Beginner Contest 158

AtCoder Beginner Contest 158

地址:https://atcoder.jp/contests/abc158/tasks

A - Station and Bus

题意:AB之间通车,给三个字符,问能否通车,水题,只要不全是A 或者全是B都能通车

#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
int main()
{
    int a = 0;
    int b = 0;
    for(int i=0;i<3;i++)
    {
        char t;
        cin>>t;
        if(t=='A') a++;
        else b++;
    }
    if(a==0||b==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
     
    return 0;
}
View Code

B - Count Balls

题意:循环

#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll t = a+b;
    ll time = n/t;
    ll y = n%t;
    ll sum = 0;
    sum+=time*a;
    if(y<=a) sum+=y;
    else sum+=a;
    cout<<sum<<endl;
         
    return 0;
}
View Code

C - Tax Increase

题意:暴力枚举,1<=A<=B<=100 所有枚举到 1500(至少1250)

#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
int main()
{
    int a,b;
    cin>>a>>b;
    int flag = 0;
    int ans = 0;
    for(int i=1;i<=1500;i++)
    {
        if(floor(i*0.08)==a&&floor(i*0.1)==b)
        {
            ans = i;
            flag = 1;
            break;
        }
        
    }
    if(flag==0) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}
View Code

D - String Formation

题意:对字符串进行如下操作:反转,在首部插入字母,在尾部插入字母

思路:数据范围较大,直接模拟会超时,可以用list,它可以快速的插入和删除元素。

一直反转会超时:其实反转后向首插入元素,相当于反转前向尾部插入元素,按照这种方法就不需要反转了,但是要注意最后输出时,如果反转了偶数次,则正序输出,如果反转了奇数次则需要逆序输出。

#include<bits/stdc++.h>
#include<vector>
#include<queue>
#include<string>
#include<list>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
int main()
{
    list<char> q;
    string s;
    cin>>s;
    int n;
    cin>>n;
    q.assign(s.begin(),s.end());
    int flag = 0;
    while(n--)
    {
        int t;
        cin>>t;
        if(t==1) flag++;
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if(f==1)
            {
                if(flag%2==0)
                {
                    q.push_front(c);
                }
                else
                {
                    q.push_back(c);
                }
            }
            else
            {
                if(flag%2!=0)
                {
                    q.push_front(c);
                }
                else
                {
                    q.push_back(c);
                }
            }
        }
    }
    if(flag%2==0)
        {
            for(auto it = q.begin();it!=q.end();it++)
            {
                cout<<*it;
            }
        }
        else
        {
            auto it = q.end();
            for(it ;it!=q.begin();it--)
            {
                if(it==q.end()) continue;
                cout<<*it;
            }
            cout<<*it;
        }
    cout<<endl;
    return 0;
}
View Code

E F 还没整明白

posted @ 2020-03-08 23:55  精神小伙儿  阅读(291)  评论(0编辑  收藏  举报