CTU Open Contest 2019

CTU Open Contest 2019

A. Beer Barrels

  • 思路:\(ans=\sum_{i=0}^k{i*C(k,i)}\) 注意\(a!=c \&\& b!=c\)还有\((a==c \&\& b==c)\)的情况

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 1010;
const int M = 1e9 + 7;

ll fac[N]={1,1},inv[N]={1,1},f[N]={1,1};
ll C(ll a,ll b){
    if(b>a)return 0;
    return fac[a]*inv[b]%M*inv[a-b]%M;
}
void init(){
    for(int i=2;i<N;i++){
        fac[i]=fac[i-1]*i%M;
        f[i]=(M-M/i)*f[M%i]%M;
        inv[i]=inv[i-1]*f[i]%M;
    }
}

ll a, b, c, k, ans;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    cin >> a >> b >> k >> c;
    if (a != c && b != c)
        ans = 0;
    else if (a == c && b == c)
        ans = k;
    else{
        for (int i = 0; i <= k; i ++ )
            ans = ((ans + i * C(k, i) % M) % M + M) % M;
    }
    cout << ans << "\n";
    return 0;
}

B. Beer Bill

  • 思路:通过第一个字符判断 再进行计算

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

ll ans;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    while(cin >> s){
        if (s[0] == '|')
            ans += s.length() * 42;
        else if (s[0] <= '9' && s[0] >= '0'){
            int tot = 0;
            ll num = 0;
            while (isdigit(s[tot])){
                num *= 10;
                num += s[tot ++ ] - '0';
            }
            ll tmp = s.length() - tot - 2;
            ans += num * max(tmp, 1ll);
        }
        else
            break;
    }
    if (ans % 10)
        ans -= ans % 10, ans += 10;
    cout << ans << ",-\n";
    return 0;
}

C. Beer Coasters

  • 思路:圆和凸多边形交面积

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 1e4 + 10;
const int eps = 1e-12;
const double pi = acos(-1.0);

struct Point
{
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx;y=yy;}
    Point operator -(Point s){return Point(x-s.x,y-s.y);}
    Point operator +(Point s){return Point(x+s.x,y+s.y);}
    double operator *(Point s){return x*s.x+y*s.y;}
    double operator ^(Point s){return x*s.y-y*s.x;}
}p[N];
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}
double len(Point a){return sqrt(a*a);}
double dis(Point a,Point b){return len(b-a);}//两点之间的距离
double cross(Point a,Point b,Point c)//叉乘
{
    return (b-a)^(c-a);
}
double dot(Point a,Point b,Point c)//点乘 
{
    return (b-a)*(c-a);
}
int judge(Point a,Point b,Point c)//判断c是否在ab线段上(前提是c在直线ab上)
{
    if (c.x>=min(a.x,b.x)
       &&c.x<=max(a.x,b.x)
       &&c.y>=min(a.y,b.y)
       &&c.y<=max(a.y,b.y)) return 1;
    return 0;
}
double area(Point b,Point c,double r)
{
    Point a(0.0,0.0);
    if(dis(b,c)<eps) return 0.0;
    double h=fabs(cross(a,b,c))/dis(b,c);
    if(dis(a,b)>r-eps&&dis(a,c)>r-eps)//两个端点都在圆的外面则分为两种情况
    {
        double angle=acos(dot(a,b,c)/dis(a,b)/dis(a,c));
        if(h>r-eps) return 0.5*r*r*angle;else 
        if(dot(b,a,c)>0&&dot(c,a,b)>0)
        {
            double angle1=2*acos(h/r);
            return 0.5*r*r*fabs(angle-angle1)+0.5*r*r*sin(angle1);
        }else return 0.5*r*r*angle;
    }else 
        if(dis(a,b)<r+eps&&dis(a,c)<r+eps) return 0.5*fabs(cross(a,b,c));//两个端点都在圆内的情况
        else//一个端点在圆上一个端点在圆内的情况
        {
            if(dis(a,b)>dis(a,c)) swap(b,c);//默认b在圆内
            if(fabs(dis(a,b))<eps) return 0.0;//ab距离为0直接返回0
            if(dot(b,a,c)<eps)
            {
                double angle1=acos(h/dis(a,b));
                double angle2=acos(h/r)-angle1;
                double angle3=acos(h/dis(a,c))-acos(h/r);
                return 0.5*dis(a,b)*r*sin(angle2)+0.5*r*r*angle3;
            }else
            {
                double angle1=acos(h/dis(a,b));
                double angle2=acos(h/r);
                double angle3=acos(h/dis(a,c))-angle2;
                return 0.5*r*dis(a,b)*sin(angle1+angle2)+0.5*r*r*angle3;
            }
        }
}

double x, y, r, ans;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    scanf("%lf%lf%lf%lf%lf%lf%lf", &x, &y, &r, &p[1].x, &p[1].y, & p[3].x, &p[3].y);
    p[2].x = p[1].x, p[2].y = p[3].y;
    p[4].x = p[3].x, p[4].y = p[1].y;
    p[5] = p[1];
    Point p0(x, y);
    for (int i = 1; i <= 5; i ++ )
        p[i] = p[i] - p0;
    p0 = Point(0, 0);
    for (int i = 1; i <= 4; i ++ ){
        double s = area(p[i], p[i + 1], r);
        if (cross(p0, p[i], p[i + 1]) > 0)
            ans += s;
        else
            ans -= s;
    }
    printf("%.4lf\n", fabs(ans));
    return 0;
}

F. Beer Marathon

  • 思路:第一次的操作先用最小的那个数作为基准点 然后计算剩下的要移动多少步 然后找到移动次数居中的那个点作为基准点移动其他点

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 1e6 + 10;

int n, k;
ll a[N];
ll ans;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i ++ )
        cin >> a[i];
    sort(a + 1, a + n + 1);
    for (int i = 2; i <= n; i ++ )
        a[i] -= 1ll * k * (i - 1);
    sort(a + 1, a + n + 1);
    int mid = (n + 1) >> 1;
    for (int i = 1; i <= n; i ++ )
        ans += abs(a[i] - a[mid]);
    cout << ans << "\n";
    return 0;
}
posted @ 2020-03-13 11:55  Misuchii  阅读(200)  评论(0编辑  收藏  举报