Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)-A,B,C題

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)-A. Contest for Robots
打一場比賽做一個比賽和知識小結。
A. Contest for Robots

A. Contest for Robots

題意:很簡單就不寫了

思路:

  1. 第一個與第二個答題情況一樣時都不選擇情況爲-1。
  2. 考慮第一個做對同時第二個做錯的情況記錄爲x,第二個做對同時第一個做錯的情況記錄爲y。
    結果就是y/x+1;
    爲什麼是y/x;對於每一個不夠除+1,夠除找最合適需要多一個也加1。

做題目時想法
關於這道題目細想:

  1. x==y && x!=0 maxx=2
  2. x>y maxx=1
  3. x==0 -1
  4. 否則 一個循環找

反思:
這個題目其實不需要用for枚舉的,自己思路不夠好
手速慢,細想花時間也有點多了。

代碼1

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define pf push_front
#define beg begin
#define e end
#define rb rbegin0
#define re rend
#define nd cout<<endl
#define all(s) s.begin(),s.end()
#define pi acos(-1.0)
#define MaxN  0x3f3f3f3f
#define MinN  0xc0c0c0c0
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+15;
int n,a[N];
int c[N],b[N];
int main()
{
    cin>>n;
    int ans=0,cnt=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int j=0; j<n; j++)
    {
        cin>>b[j];
    }
    for(int i=0; i<n; i++)
    {
        if(b[i]==1&&a[i]!=1)
        {
            ans++;
        }
        else if(a[i]==1&&b[i]!=1)
        {
            cnt++;
        }
    }
    if((ans==0&&cnt==0)||cnt==0)
        cout<<"-1"<<endl;
    else if(ans==cnt)
        cout<<"2"<<endl;
    else if(cnt>ans)
        cout<<"1"<<endl;
    else
    {
        int y=0;
        int u=cnt;
        for(int i=1;i<=1000;i++)
        {
            u=cnt*i;
            if(u>ans)
            {
                y=i;
                break;
            }
        }
        cout<<y<<endl;
    }
    return 0;
}

代碼2

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define pf push_front
#define beg begin
#define e end
#define rb rbegin0
#define re rend
#define nd cout<<endl
#define all(s) s.begin(),s.end()
#define pi acos(-1.0)
#define MaxN  0x3f3f3f3f
#define MinN  0xc0c0c0c0
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+15;
int n,a[105],b[105];
int main()
{
    int x=0,y=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
    {
        if(a[i]&&!b[i])
            x++;
        if(!a[i]&&b[i])
            y++;
    }
    printf("%d",x?y/x+1:-1);
    return 0;
}

B. Journey Planning

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)-B. Journey Planning

B. Journey Planning

題意:

思路:

代碼1

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define pf push_front
#define beg begin
#define e end
#define rb rbegin0
#define re rend
#define nd cout<<endl
#define all(s) s.begin(),s.end()
#define pi acos(-1.0)
#define MaxN  0x3f3f3f3f
#define MinN  0xc0c0c0c0
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+15;
int n;
long long f[1000000]= {0};
int b[200002];
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&b[i]);
        if(b[i]-i+400000>=0)
            f[b[i]-i+400000]+=b[i];
    }
    ll ans=-1;
    for(int i=0; i<1000000; i++)
    {
        if(ans<f[i])
            ans=f[i];
//  if(i<100)printf("%d\n",f[i]);
    }
    printf("%lld",ans);
    return 0;
}

代碼2

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define pf push_front
#define beg begin
#define e end
#define rb rbegin0
#define re rend
#define nd cout<<endl
#define all(s) s.begin(),s.end()
#define pi acos(-1.0)
#define MaxN  0x3f3f3f3f
#define MinN  0xc0c0c0c0
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+15;
int main()
{
    map <int, long long> M;
    int n, x;
    long long ans = 0LL;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> x, M[i - x] += (long long)x, ans = max(ans, M[i - x]);
    cout << ans;
    return 0;
}

C. Remove Adjacent

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)-C. Remove Adjacent

C. Remove Adjacent

題意:

小寫字母構成的字符串s,讓你去不斷的刪除字母,刪除的規則是:將當前字母s[i] 前一個或者後一個 與當前的差爲1,則刪除當前這個。最後要求你刪除字母的操作必須是最大。

思路:

按照題意刪除,要想最大,那麼我們就需要從字符串中字母字典序最大的開始考慮刪除。

關於這道題目:

當時的思考是如思路所寫,然後想怎麼實現的時候,在想這個每次找一下最大,時間複雜度允許,但寫起來不是最好,於是,再考慮一些字母的性質,最大的爲’z‘ 那麼我們倒過來當前的最大的‘z’,然後判斷s[i] 是否與之相等。相等判斷是否刪除當前的s[i]

反思:

一開始想的時候並沒有用string考慮 導致自己花了一些時間去想怎麼刪除後重構字符串。
所以關於string 今天早上打算細學深思。

代碼:

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define pf push_front
#define beg begin
#define e end
#define rb rbegin0
#define re rend
#define nd cout<<endl
#define all(s) s.begin(),s.end()
#define pi acos(-1.0)
#define MaxN  0x3f3f3f3f
#define MinN  0xc0c0c0c0
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+15;
string s;
int n;
int main()
{
    cin>>n>>s;
    int ans = 0;
    for(char C = 'z'; C > 'a'; C--)
        for(int i = 0; i <s.size(); i++)
        {
            if(s[i] != C)
                continue;
            if((s[i - 1] + 1 == s[i] && i != 0) || s[i + 1] + 1 == s[i] && i != s.size() - 1)
            {
                s.erase(s.begin() + i);
                i = -1;
                ans += 1;
            }
        }
    cout<<ans<<endl;
    return 0;
}

String知識的回顧和加深:

一點都不會的可以去看看這篇博客

或者新寫的一篇博客
s.size()

返回s 中字符的字符個數

s.erase( p )

刪除迭代器p指向的元素,返回一個迭代器,指向被刪除元素後面的元素
也就是刪除p這個位置的元素,然後後面的元素往前移一位。

String 的遍歷

string s;
string::iterator it;//迭代器
for(it=s.begin();it!=s.end();++it)

代碼

#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
    string s("wow wow");
    string::iterator it;
    for(it=s.begin();it!=s.end();++it)
        cout<<*it<<endl;
    for(int i=0;s[i];i++)
        cout<<s[i]<<endl;
    cout<<s<<endl;
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章