Codeforces Round #432 题解

比赛链接:http://codeforces.com/contest/851
A. Arpa and a research in Mexican wave
题意:balabala
解法:找个规律。。
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,k,t;
    cin>>n>>k>>t;
    if(t<=k) return 0*printf("%d\n", t);
    else return 0*printf("%d\n", k-(t>=n?t-n:0));
}

B. Arpa and an exam about geometry
题意:给你3个点的坐标,问你是否能找到一个点,以该点为中心旋转一定的角度使得a与b重合,b与c重合
解法:直接判断只要两个线段长度相同而且三个点不在同一直线上就行了
#include <bits/stdc++.h>
using namespace std;
struct point{
    double x,y;
    point(){}
    point(double _x, double _y){
        x = _x;
        y = _y;
    }
}a[3];
point operator-(const point &x, const point &y){
    return point(x.x-y.x,x.y-y.y);
}
double xmul(const point &x, const point &y){
    return x.x*y.y-y.x*x.y;
}

int main(){
    for(int i=0; i<3; i++) cin>>a[i].x>>a[i].y;
    for(int i=0; i<3; i++){
        for(int j=i+1; j<3; j++){
            int k = 3-i-j;
            if(xmul(a[i]-a[k],a[j]-a[k])==0){
                return 0*puts("No");
            }
        }
    }

    for(int i=0; i<3; i++){
        for(int j=i+1; j<3; j++){
            int k = 3-i-j;
            if(k!=1) continue;
            point p1 = a[i]-a[k];
            point p2 = a[j]-a[k];
            if(p1.x*p1.x+p1.y*p1.y==p2.x*p2.x+p2.y*p2.y){
                return 0*puts("Yes");
            }
        }
    }
    return 0*puts("No");
}
C. Five Dimensional Points
题意:给你n个五维空间的点,求出有多少个点他与任意两点连成的线段的夹角不是锐角的。
解法:固定一个点,求出其他点的向量,然后排序,计算相邻的即可。
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-12;
const int maxn = 1010;
struct point{
    double a,b,c,d,e;
    point(){}
    point(double _a, double _b, double _c, double _d, double _e){\
        a = _a;
        b = _b;
        c = _c;
        d = _d;
        e = _e;
    }
}p[maxn];
point operator-(const point &a, const point &b){
    return point(a.a-b.a,a.b-b.b,a.c-b.c,a.d-b.d,a.e-b.e);
}
bool cmp(const point &a, const point &b){
    if(a.a!=b.a) return a.a<b.a;
    else if(a.b!=b.b) return a.b<b.b;
    else if(a.c!=b.c) return a.c<b.c;
    else if(a.d!=b.d) return a.d<b.d;
    else return a.e<b.e;
}
double dot(const point &a, const point &b){
    return a.a*b.a+a.b*b.b+a.c*b.c+a.d*b.d+a.e*b.e;
}
double length(const point &a){
    return sqrt(a.a*a.a+a.b*a.b+a.c*a.c+a.d*a.d+a.e*a.e);
}
double angle(const point &a, const point &b){
    return acos(dot(a,b)/length(a)/length(b));
}
vector <point> v;
vector <int> ans;
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%lf %lf %lf %lf %lf", &p[i].a,&p[i].b,&p[i].c,&p[i].d,&p[i].e);
    }
    for(int i=0; i<n; i++){
        v.clear();
        for(int j=0; j<n; j++){
            if(j==i) continue;
            v.push_back(p[j]-p[i]);
        }
        sort(v.begin(),v.end(),cmp);
        bool ok = 1;
        for(int j=0; j<(int)v.size()-1; j++){
            if(2.0*angle(v[j],v[j+1])<PI){
                ok=0;
                break;
            }
        }
       if(v.size()>=2&&2.0*angle(v[0],v[v.size()-1])<PI){
            ok = 0;
        }
        if(ok) ans.push_back(i+1);
    }
    printf("%d\n", (int)ans.size());
    for(int i=0; i<(int)ans.size(); i++) printf("%d ", ans[i]);
    printf("\n");
    return 0;
}
D. Arpa and a list of numbers
题意:有一个序列,我们有两种操作:删除某个数,代价为 x 。将某个数的值加一,代价为 y 。现在我们想让这个序列所有数的 gcd 大于 1 ,求最小的代价。
解法:要让序列所有数的 gcd 大于 1 ,我们可以枚举所有的素因子。对于每一个素因子 i ,计算当前情况下所需要的最小代价,假设有一个数为 x ,且 i 不是 x 的因子,当 1×x>(ix%i)×y 时显然我们可以选择将 x 加到 i 的倍数,否则删除这个数。找最小值即可。不过这里我们还需要做点剪枝,当不含有 i 这个因子的数的个数乘以 min(x,y) 大于当前已知的最小结果时可以不做处理。显然, min(x,y) 中的 x 相当于删除所有数,而 y 相当于我们对序列中的每一个数执行最多一次操作让其变成偶数(或者特殊的奇数),此时的 gcd 至少为 2 。好像暴力枚举gcd可以卡过。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
typedef long long LL;
LL n,x,y,a[maxn],sum[maxn];
bool vis[maxn];

int main(){
    scanf("%lld%lld%lld",&n,&x,&y);
    for(int i=1; i<=n; i++){
        scanf("%lld",&a[i]);
        sum[a[i]]++;
    }
    LL ans = __INT64_MAX__;
    for(int i=2; i<maxn; i++){
        if(!vis[i]){
            LL cnt = sum[i];
            for(int j=i+i; j<maxn; j+=i){
                vis[j] = 1;
                cnt += sum[j];
            }
            if((n-cnt)*min(x,y)<ans){
                LL val = 0;
                for(int j=1; j<=n; j++) if(a[j]%i) val += (x>y*(i-a[j]%i)?y*(i-a[j]%i):x);
                ans = min(ans, val);
            }
        }
    }
    return 0*printf("%lld\n",ans);
}
E. Arpa and a game with Mojtaba


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n, x, tot=0, Ans=0, prime[maxn];
bool isprime[maxn];
map<int,int>sg,st;
void init(){
    memset(isprime,true,sizeof(isprime));
    isprime[1]=false;
    for(int i=2;i<maxn;i++){
        if(isprime[i]) prime[++tot]=i;
        for(int j=1;j<=tot&&i*prime[j]<maxn;j++){
            isprime[i*prime[j]]=false;
            if(i%prime[j]==0) break;
        }
    }
}
void gao(int x){
    for(int i=1;prime[i]*prime[i]<=x;i++){
        int t=0;
        while(x%prime[i]==0){
            x/=prime[i];
            t++;
        }
        if(t) st[prime[i]]|=1<<(t-1);
    }
    if(x!=1) st[x]|=1;
}
int getsg(int x){
    if(x==0) return 0;
    if(sg.count(x)) return sg[x];
    map<int,int>vis;
    int p=x,t=0;
    while(p) p>>=1,t++;
    for(int i=1;i<=t;i++){
        vis[getsg((x>>i)|(x&((1<<i-1)-1)))]=1;
    }
    for(int i=0;;i++) if(!vis[i]) return sg[x]=i;
}
int main(){
    init();
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&x), gao(x);
    for(map<int,int>::iterator it=st.begin(); it!=st.end(); it++) Ans ^= getsg(it->second);
    if(Ans) puts("Mojtaba");
    else puts("Arpa");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值