Comet OJ - Contest #8 题解

本文探讨了如何使用sort函数找到n个字符串中字典序最小的一个,并提出了一种方法来优化数值运算效率,减少大数运算的时间复杂度,通过预计算和巧妙的数学公式加速求解过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A-杀手皇后

题目:给出n个字符串,求按照字典序排列的最小的。

  • 排序;字典序
  • 万能的sort函数啊
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int n; cin >> n;
    string str[1010];
    for(int i=0; i<n; i++)
        cin >> str[i];
    sort(str, str+n);
    cout << str[0] << endl;
    return 0;
}

B-支援城市

题目:n个数,对每个数,求它与其他每个数的差的平方的和。

主要在控制时间上,本来解决了思路上的问题,但是好像还有个大数运算的问题,这里先放还没有处理大数运算的代码。

  • 未AC的代码
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
const int maxn = 1000000;
int a[maxn];
ll sum1(0), sum2(0);
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        sum1 += a[i]*a[i];
        sum2 += a[i];
    }
    printf("%lld", (n - 2) * a[0] * a[0] + sum1 - 2 * a[0] * (sum2 - a[0]) );
    for(int i=1; i<n; i++)
        printf(" %lld", (n - 2) * a[i] * a[i] + sum1 - 2 * a[i] * (sum2 - a[i]));
  printf("\n");
    return 0;
}
# YOLOv5 🚀 requirements # Usage: pip install -r requirements.txt # Base ------------------------------------------------------------------------ gitpython ipython # interactive notebook matplotlib>=3.2.2 numpy>=1.18.5 opencv-python>=4.1.1 Pillow>=7.1.2 psutil # system resources PyYAML>=5.3.1 requests>=2.23.0 scipy>=1.4.1 thop>=0.1.1 # FLOPs computation torch>=1.7.0 # see https://pytorch.org/get-started/locally (recommended) torchvision>=0.8.1 tqdm>=4.64.0 # protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012 # Logging --------------------------------------------------------------------- tensorboard>=2.4.1 # clearml>=1.2.0 # comet # Plotting -------------------------------------------------------------------- pandas>=1.1.4 seaborn>=0.11.0 # Export ---------------------------------------------------------------------- # coremltools>=6.0 # CoreML export # onnx>=1.9.0 # ONNX export # onnx-simplifier>=0.4.1 # ONNX simplifier # nvidia-pyindex # TensorRT export # nvidia-tensorrt # TensorRT export # scikit-learn<=1.1.2 # CoreML quantization # tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos) # tensorflowjs>=3.9.0 # TF.js export # openvino-dev # OpenVINO export # Deploy ---------------------------------------------------------------------- # tritonclient[all]~=2.24.0 # Extras ---------------------------------------------------------------------- # mss # screenshots # albumentations>=1.0.3 # pycocotools>=2.0 # COCO mAP # roboflow # ultralytics # HUB https://hub.ultralytics.com
最新发布
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值