其他分享
首页 > 其他分享> > 2020.04.19 QFNU-ACM 个人赛

2020.04.19 QFNU-ACM 个人赛

作者:互联网

[A - Buggy Sorting]

这个题讲的就是一个人写了一个错误的排序算法,要求给出一个反例,使他的程序无法工作,

说实话我都不是很明白怎么a的……反正

如果输入1或2应当输出-1

除此之外就按从大到小输出一排数组就好,

因为他的算法不能完成正常的冒泡排序

所以给出一个从大到小的数列就可以验证他不对喽

代码:

//去吧马里奥!把AC公主救回来!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;


int main(){
    int n;
    cin >> n;
    if(n == 1){
        cout << -1;
    }else if(n == 2){
        cout << -1;
        
    }else{
        for(int i = n;i >= 1;i--){
            cout << i << ' ';
        }
        cout << endl;
        
    }
    return 0;
}

[B - Increase and Decrease]

这个题说给出一段数组,其中可以对其中两个数进行操作,将任意两个数一个+1一个-1,之后问最多可以形成多少个相同的数,输出个数

其实可以这样想,两个数一个+1一个-1,把两个数相加之后相当于和没变,也就是整个数组的总和没变,

找一下规律

判断总和是不是可以被n整除就可以了

如果可以整除,比如1 2 3,相加得6,6可以被3整除,等于2,也就是所有数字都可以等于2,输出3就可以了

别的数同理,如果不能整除,那肯定最后剩下一个数,唯一一个不能和其他数统一的数,因此输出n-1

代码:

//去吧马里奥!把AC公主救回来!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;

int a[100005];

int main(){
    int n;
    cin >> n;

    int sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
    }
    if(sum % n == 0){
        cout << n << endl;
    }else{
        cout << n-1 << endl;
    }
}

 

标签:QFNU,19,....,2020.04,long,####,int,######,include
来源: https://www.cnblogs.com/CCCCrack/p/12750573.html