1. 程式人生 > >contest 1.13

contest 1.13

lose ont main scanf info str bound icp test

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