Codeforces 677 - A/B/C/D/E - (Undone)

連接:html


A - Vanya and Fence - [水]

AC代碼:ios

#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 - [模擬]

應該就是http://www.javashuo.com/article/p-rklsnmoi-d.html我這篇遠古文章中記錄的這道題目的來源。c++

模擬的時候注意不要一秒一秒的模擬,而且注意使用long long類型,就能夠了。spa

AC代碼:code

#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$ 進制數對,使得他們的按位與結果和給出的這個數字相同。htm

題解:轉成二進制觀察一下,給定的數字其全部爲 $0$ 的位置,對應到數對能夠產生三種選擇:「$0,1$」、「$1,1$」、「$1,0$」,因此就統計一下二進制下 $0$ 出現的次數,記爲 $x$,求 $3^x$ 便可。blog

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)

相關文章
相關標籤/搜索