第二届中国计量大学ACM程序设计竞赛个人赛(同步赛)

本文详细解析了第二届中国计量大学ACM程序设计竞赛个人赛的题目,包括A题的排序问题,B题的数的分组,F题的最长上升和非上升子序列,G题的寻找绝对差值之和,I题的logs摆法计算,以及L题的解题思路。每个题目都提供了思路和代码实现。
摘要由CSDN通过智能技术生成

原题地址
A题
题意:排序
思路:主要卡时间,用快读
代码:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int read() {
   
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
   
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
   
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar();
    }
    return w? -num: num;
}

//快速写
inline void write(int x)
{
   
    if(x<0) {
   
        putchar('-');
        x = -x;
    }
    if(x>9) write(x / 10);
    putchar(x % 10 + '0');
}

int arr[1000000];
int main()
{
   
    int n, k;n = read();
    while(n--){
   
        int t = read();
        for(int i=0;i<t;i++){
   
            arr[i]=read();
        }
        sort(arr,arr+t);
        for(int i=0;i<t;i++){
   
            if(i)printf(" ");
            write(arr[i]);
        }printf("\n");
    }
    return 0;
}

B题
题意:给你n,m,然后让你分两组,一组是能被m整除的,两组是其他的
思路:一开始超时了在我直接遍历找能被整除的数,后来换了一种写法,就过了
代码:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int read() {
   
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
   
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
   
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值