vj补题计算线段交点个数+相交圆的最小圆 +在圆中循环+区间问题

题目链接题目链接

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;//longlong比较安全

map<pair<LL, LL>, LL> q;//用来存其斜率 (不用一个都double存因为其误差太大)
map<pair<pair<LL, LL>, LL>, LL> s;//(用来存斜率+截距)

int main()
{
    ios::sync_with_stdio(0);//不关同步流超时
    cin.tie(0),cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
       q.clear();
       s.clear();
        LL ans = 0;
        int n;
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            LL x1, x2, y1, y2;
        //    scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
        cin>>x1>>y1>>x2>>y2;
            LL gcd = __gcd(x1 - x2, y1 - y2);
            LL A = ++q[{(y1 - y2) / gcd, (x1 - x2) / gcd}];//画到最简
            LL B = ++s[{{(y1 - y2) / gcd, (x1 - x2) / gcd}, (x1*y2-x2*y1)/gcd}];//(x1y2-x2y1)/gcd存截距
            ans += i - A + B;(减去斜率相等的+上截距相等的;
        }
        cout << ans << endl;
    }

    return 0;
}

圆的题目链接

基本大意

数学知识:相交的圆  他的半径就是他么两个((r1+r2)-圆心之间的距离)除以二

坐标就是用相似三角形的进行补充

#include<bits/stdc++.h>

using namespace std;

int main()
{
    double x1,x2,x3,y1,y2,y3,r1,r2,r3;
    cin>>x1>>y1>>r1>>x2>>y2>>r2;
    double k=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
    r3=(r1+r2-k)/2.0;
    x3=(k-r2+r3)/k*(x2-x1)+x1;
     y3=(k-r2+r3)/k*(y2-y1)+y1;
     printf("%.15lf %.15lf %.15lf",x3,y3,r3);
    return 0;
}

螺旋的求最小

首先她就不是锯齿下降最小(锯齿是最后一直冲击最下边小的那行)  而是螺旋最小(最后冲击中间没有合并的)

#include<bits/stdc++.h>

using namespace std;


typedef long long LL;
int main()
{
    LL n,m;

    LL left;
     
    cin>>n>>m;
    LL c=n%m;//中间空的;
    n=n*n-m*m-c*c;//用螺旋可以去掉的全部减去螺旋不能到的和中间剩余的
    cout<<(n+m-1)/m+c;//(n+m-1)/m是螺旋的的距离  +中间未到的  
    return 0;
}

 

主义:在不断进行取的时候到2p之后就是重复的了  

#include<bits/stdc++.h>

using namespace std;


typedef long long LL;
const int N=1e7+5;
 LL vis[N];
int main()
{
 
    vis[0]=1;
   LL  n;
    LL m;
    cin>>n>>m;

    LL now=0;
     for(LL i=1;i<=min(m,2*n);i++)//等差数列1+2+。。。+p(a1+an)*n/2在2p的时候==0 就开始重复
     {
        now=(now+i)%n;//进行标记  别忘了了 (now+i)%n标记
        vis[now]=1;
     }
     LL sum=0;
     for(LL i=0;i<n;i++)
     {
        sum+=vis[i];
     }
     cout<<sum<<endl;
    return 0;
}

区间问题处理区间问题

#include<bits/stdc++.h>

using namespace std;


const int N =500000+10;
int a[N];
int pos[N];//记录正数出现的位置
stack<int>q;//记录答案
int main()
{
    memset(pos,0,sizeof(pos));
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
   int cnt=0;
   for(int i=n-1;i>=0;i--)
   {
    if(a[i]>0)
    { 
        cnt++;//大于零直接进去
        pos[a[i]]=i;//记录一下这个的位置
        q.push(cnt);//存储结果
    }
    else{
        if(!pos[-a[i]]) //如果从后往前没有这个数字就继续就可以
        {
            cnt++;
            q.push(cnt);
        }
        else
        {
            cnt=min(cnt+1,pos[-a[i]]-i);//如果存在就看看和现在+1和原先的位置-i比较取比较小的情况  因为可能中间早就断了。
            q.push(cnt);
        }
    }
   }
   while(q.size()) 
   {
    cout<<q.top()<<" ";
    q.pop();
   }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值