2021杭电多校3

在这里插入图片描述

T1004 Game on Plane
在这里插入图片描述

题意:给n条直线,每轮一个k,A先选k条,B再画一条,计算B画的这条线与A选的这k条线的交点,A希望这个值尽可能大,B反之。问k从1到n递增时候,这个最小为多少。

idea:在这里插入图片描述
1)HDOJ不要用读入优化 !!!!
(如图:)
在这里插入图片描述

2)cmp别别手欠多打个=

ACcode:

#include <cstdio>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define x first
#define y second
#define PII pair<LL,LL>

using namespace std;
PII u,v,AB;
LL t,num[1001010];

LL gcd(LL a,LL b)
{
	LL c;
    while( b )
    {
    	c = a;
    	a = b;
    	b = c%a;
	}
	return a;
}
LL n,m;
PII jian( PII a,PII b )
{
    PII ans,temp;
    ans.x = b.x-a.x;
    ans.y = b.y-a.y;
    if( ans.x<0 )
    {
        ans.x = -ans.x;
        ans.y = -ans.y;
    }
    temp = ans;
    if( temp.x<0 ) temp.x = -temp.x;
    if( temp.y<0 ) temp.y = -temp.y;
    LL g = gcd( temp.x , temp.y );
    ans.x /= g;
    ans.y /= g;
    return ans;
}
bool cmp(LL x,LL y)
{
    return x>y;
}
LL tot = 0;
map<PII,LL> ma1;
int bucket[100010];
void solve()
{
    tot = 0;
    ma1.clear();
    scanf("%lld",&n);
    for(LL i=1;i<=n;i++)
    {
        scanf("%lld %lld %lld %lld",&u.x,&u.y,&v.x,&v.y);

        if( u.x==v.x )
        {
            AB.x = 0;
            AB.y = 1;
        }
        else if( u.y==v.y )
        {
            AB.x = 1;
            AB.y = 0;
        }
        else AB = jian( u,v );

        if( ma1[AB]==0 )
        {
            tot++;
            num[tot] = 0;
            ma1[AB] = tot;
            num[tot]++;
        }
        else
        {
            LL tag = ma1[AB];
            num[tag]++;
        }
    }

    sort(num+1,num+tot+1,cmp);

    LL j = 1,maxx=0,h = 1;
    for(;j<=tot;j++)
    {
        h++;
        num[j]--;
        printf("%lld\n",j-1);
    }
    
    maxx = j-2;
    for(;h<=n;j++)
    {
        h++;
        if( j>tot||num[j]==0 )
        {
            j = 1;
        }
        num[j]--;
        if( j==1 )
        {
            printf("%lld\n",maxx);
        }
        else
        {
            maxx++;
            printf("%lld\n",maxx);
        }
    }

}
int main()
{
    scanf("%lld",&t);
    while( t-- )
        solve();
    return 0;
}

后面补T1010…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值