Codeforces 677

链接:


A - Vanya and Fence - [水]

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
int n,h;
int main()
{
    cin>>n>>h;
    int ans=0;
    for(int i=1,a;i<=n;i++)
    {
        cin>>a;
        if(a<=h) ans++;
        else ans+=2;
    }
    cout<<ans<<endl;
}

B - Vanya and Food Processor - [模拟]

应该就是https://www.cnblogs.com/dilthey/p/6804187.html我这篇远古文章中记录的这道题目的来源。

模拟的时候注意不要一秒一秒的模拟,并且注意使用long long类型,就可以了。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll n,h,k,a[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin>>n>>h>>k;
    for(int i=1;i<=n;i++) cin>>a[i];

    int p=1;
    ll t=0, cnt=a[1];
    while(p<=n)
    {
        while(p+1<=n && cnt+a[p+1]<=h) cnt+=a[++p];
        if(cnt>k) t+=cnt/k, cnt%=k;
        else cnt=0, t++;

        if(p==n && cnt==0) break;
    }
    cout<<t<<endl;
}

C - Vanya and Label - [快速幂]

题意:给你一个 $64$ 进制的数字,让你找出所有等长的两个 $64$ 进制数对,使得他们的按位与结果和给出的这个数字相同。

题解:转成二进制观察一下,给定的数字其所有为 $0$ 的位置,对应到数对可以产生三种选择:“$0,1$”、“$1,1$”、“$1,0$”,所以就统计一下二进制下 $0$ 出现的次数,记为 $x$,求 $3^x$ 即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef bitset<6> B;
typedef long long ll;
const int mod=1e9+7;
string s;
int num[300];
void init()
{
    for(char i='0';i<='9';i++) num[i]=i-'0';
    for(char i='A';i<='Z';i++) num[i]=i-'A'+10;
    for(char i='a';i<='z';i++) num[i]=i-'a'+36;
    num['-']=62, num['_']=63;
}
ll fpow(ll a,ll n)
{
    ll res=1, base=a%mod;
    while(n)
    {
        if(n&1) res*=base, res%=mod;
        base*=base, base%=mod;
        n>>=1;
    }
    return res%mod;
}
int main()
{
    init();
    cin>>s;
    ll res=0;
    for(int i=0;i<s.size();i++) res+=6LL-((B)num[s[i]]).count();
    cout<<fpow(3,res)<<endl;
}

D - Vanya and Treasure- [DP+优先队列BFS]


E - Vanya and Balloons - (Undone)

原文地址:https://www.cnblogs.com/dilthey/p/10462028.html