码迷,mamicode.com
首页 > 其他好文 > 详细

contest 1.13

时间:2019-01-13 18:05:04      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:algorithm   splay   pre   ble   src   amp   while   图片   ima   

A.发财兔1A

技术分享图片

O(nlogn)

技术分享图片
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
 
ll n,num;
ll a[1000005];
ll b[1000005];
ll cnt[1000005];
 
ll getid(ll x){
  return lower_bound(b+1,b+1+num,x)-b;
}
 
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=a[i];
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    num=unique(b+1,b+1+n)-(b+1);
    for(ll i=1;i<=n;i++){
        ll id=getid(a[i]);
        cnt[id]++;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll now=1;
        while(now<=2*a[n]){
            if(now<a[i]||now-a[i]<a[i]) {now*=2;continue;}
            ll id=getid(now-a[i]);
            if(b[id]==now-a[i]){
              ans+=cnt[id];
              if(now-a[i]==a[i]) {ans--;cnt[getid(a[i])]--;}
            }
            now*=2;
        }
    }
    printf("%lld\n",ans);
    return 0;
}
 
View Code

 

C.发财兔1C

E.bomb

技术分享图片
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
 
map<double,int> mp;
 
struct Node{
  int x,y;
}node[1205];
 
double getk(Node a,Node b){
  double x=a.x-b.x;
  double y=a.y-b.y;
  if(y==0) return 0;
  else if(x==0) return inf;
  else return y*1.0/(x*1.0);
}
 
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&node[i].x,&node[i].y);
    }
    int ans=1;
    for(int i=1;i<=n;i++){
        int cnt=1;
        mp.clear();
        for(int j=1;j<=n;j++){
            if(j==i) continue;
            double k=getk(node[i],node[j]);
            mp[k]++;
            cnt=max(cnt,mp[k]+1);
        }
        ans=max(ans,cnt);
    }
    printf("%d\n",ans);
    return 0;
}
 
View Code

 

F.matrix

contest 1.13

标签:algorithm   splay   pre   ble   src   amp   while   图片   ima   

原文地址:https://www.cnblogs.com/lllxq/p/10263221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!