2024牛客暑期多校训练营4赛后补题

2024牛客暑期多校训练营赛后补题

G.Horse Drinks Water

题意:将军饮马。

#include <bits/stdc++.h>
#define maxn 201

using namespace std;
bool rd[maxn][maxn];

int a[maxn],dp[maxn],p[maxn],pos;
int solve(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    double cnt=min(sqrt(pow(x1+x2,2)+pow(abs(y1-y2),2)),sqrt(pow(abs(x1-x2),2)+pow(y1+y2,2)));
    printf("%.10lf\n",cnt);
    return 0;
}
signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

I.Friends

题意:有 n n n个人站成一排,从左到右依次为1到 n n n。在这些人中,有$ m 对朋友。定义区间 m对朋友。定义区间 m对朋友。定义区间[l,r]$为友好当且仅当区间内的每对人都是朋友。问有多少个友好间歇?
题解:从左向右枚举。

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int sum[N];
int main() 
{
    int n, m;
    cin>>n>>m;
    vector< set<int> >a(n + 1);
    vector<int> x(n + 2);
    for(int i=1;i<=m;i++)
    {
        int x, y;
        cin>>x>>y;
        a[x].insert(y);
    }
    for(int i=n;i>=1;i--) 
    {
        int j = i;
        while ( ( i == j || a[i].count(j) ) && x[i] <= x[i + 1] ) 
        {
            x[i]++, j++;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++) 
    {
        ans += x[i];
    }
    cout<<ans<<endl;
    return 0;
}
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yi壹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值