# CTU Open Contest 2019 AB题

A: Beer Barrels

1.先考虑特殊情况：

(1) 如果C不是A或者B 则输出0

(2) 如果K = 0 则输出0

(3) 如果A==B 则输出K

2.再考虑一般情况:

AC代码：

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll pow(ll a,ll b,ll mod)
{
ll ans = 1;
while(b!=0)
{
if(b%2==1) ans=(a%mod*ans%mod)%mod;

a = (a%mod*a%mod)%mod;
b = b/2;
}
return ans%mod;

}
int main()
{
ll mod = 1000000007;
ll a,b,k,c;
cin>>a>>b>>k>>c;
if(k==0) cout<<"0"<<endl;
else if(a==b) cout<<k<<endl;
else if(c!=a&&c!=b) cout<<"0"<<endl;
else
{
ll f[1010];
f[0] = 1;
for(int i=1;i<=1000;i++)
{
f[i] = (f[i-1]*i)%mod;
}
ll ans = 0;
for(int i=1;i<=k;i++)
{
ll t = (i%mod*f[k]%mod* pow(f[i],mod-2,mod)%mod * pow(f[k-i],mod-2,mod)%mod)%mod;
ans = (ans%mod +t%mod)%mod;
}
cout<<ans<<endl;

}
return 0;
}

B: Beer Bill

AC代码：

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {

string s;
int ans = 0;
while(cin>>s)
{
int count = 0;
if(s[0]=='|')
{
count = 42*s.length();
}else{
int x = 0;
int sum = 1;
for(int i=0;i<s.length();i++){
if(s[i]>='0'&&s[i]<='9'){
x = x*10+(s[i]-'0');
}
if(s[i]=='|') sum++;
}
if(sum!=1) sum--;
count = x*sum;

}
ans+=count;

}
if(ans%10!=0)
{
int t = ans/10+1;
ans = t*10;
}
cout<<ans<<",-"<<endl;

return 0;
}

posted @ 2020-02-27 22:05  精神小伙儿  阅读(...)  评论(...编辑  收藏