蓝桥杯百校真题大联赛第4期(三)

A组

平面分割

#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#define x first
#define y second

using namespace std;
const int N = 1010;
typedef pair<long double, long double> PDD;
typedef long long LL;

LL ans;
PDD p;
long double s[N][2];
bool st[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++ )
    {
        cin >> s[i][0] >> s[i][1];
        set<PDD> S;
        for (int j = 0; j < i; j ++ )
        {
            if (st[j]) continue;
            if (s[i][0] == s[j][0])
            {
                if (s[i][1] == s[j][1])
                {
                    st[i] = true;
                    break;
                }
                else continue;
            }
            
            p.x = (s[j][1] - s[i][1]) / (s[i][0] - s[j][0]);
            p.y = s[i][0] * p.x + s[i][1];
            S.insert(p);
        }
        if (!st[i]) ans += S.size() + 1;
    }
    cout << ans + 1 << endl;
    return 0;
}

成绩分析

#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码
  int minn = 110, maxn = -1;
  double avg;
  double n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i ++ )
  {
    int x;
    cin >> x;
    minn = min(minn, x);
    maxn = max(maxn, x);
    sum += x;
  }
  avg = sum / n;
  printf("%d\n%d\n%.2lf", maxn, minn, avg);
  return 0;
}

B组

路径

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 2200;

int g[N][N];
int dist[N];
int n = 2021;
bool st[N];

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

void dijkstra()
{
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    
    for (int i = 1; i <= n; i ++ )
    {
        int t = -1;
        for (int j = 1; j <= n; j ++ )
            if (!st[j] && (t == -1 || dist[j] < dist[t]))
                t = j;
        
        st[t] = true;
        for (int j = 1; j <= n; j ++ )
            dist[j] = min(dist[j], dist[t] + g[t][j]);
    }
}

int main()
{
    memset(g, 0x3f, sizeof g);
    for (int i = 1; i <= 2021; i ++ )
        for (int j = max(i - 21, 1); j <= min(i + 21, n); j ++ )
        {
            int d = gcd(i, j);
            g[i][j] = g[j][i] = i * j / d;
        }
    
    dijkstra();
    
    cout << dist[n] << endl;
    
    return 0;
}

时间显示

#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long LL;

using namespace std;

int main()
{
    LL n, h, m, s;
    cin >> n;
    
    n /= 1000;
    h = n / 3600 % 24;
    
    n %= 3600;
    s = n % 60;
    m = n / 60;
    
    printf("%02lld:%02lld:%02lld", h, m, s);
    return 0;
}

C组

快速排序


#include<bits/stdc++.h>
using namespace std;
int quick_select(int a[], int l, int r, int k) {
    int p = rand() % (r - l + 1) + l;
    int x = a[p];
    {int t = a[p]; a[p] = a[r]; a[r] = t;}
    int i = l, j = r;
    while(i < j) {
        while(i < j && a[i] < x) i++;
        if(i < j) {
            a[j] = a[i];
            j--;
        }
        while(i < j && a[j] > x) j--;
        if(i < j) {
            a[i] = a[j];
            i++;
        }
    }
    a[i] = x;
    p = i;
    if(i - l + 1 == k) return a[i];
    if(i - l + 1 < k) return quick_select( a, i, r, k ); //填空   //通过观察对比else的quick_select参数可直接写出结果
    else return quick_select(a, l, i - 1, k);
}
    
int main()
{
    int a[100];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    cout<<quick_select(a, 0, n-1, 5);
    return 0;
}

凑算式

#include <bits/stdc++.h>
using namespace std;
int a[] = {1,2,3,4,5,6,7,8,9};
int main()
{
  // 请在此输入您的代码
  long long ans = 0;
  sort(a, a + 9);
  do{
    if(a[0] + (a[1] * 1.0 / a[2]) + (a[3] *100 + a[4] * 10 + a[5]) * 1.0/ (a[6] * 100 + a[7] * 10 + a[8]) == 10)
      {
        ans ++;
       }
  }while(next_permutation(a , a + 9));
  cout <<ans << endl;
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Shirandexiaowo

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

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

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

打赏作者

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

抵扣说明:

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

余额充值