四月七号水题日常

1550: 换座位

Time Limit: 1 Sec  Memory Limit: 256 MB
Submit: 87  Solved: 22
[Submit][Status]

Description

       有N个人(编号为1~N)按编号顺时针围成一圈,相邻的两个人可以相互交换位置,问最少交换多少次可以使N个人按编号逆时针坐?

Input

       第一行输入一个T(T<=32767),表示测试用例数量。后T行每行输入一个N(1<=N<=32767)。

Output

       每组测试用例输出一行,包含样例编号和答案,具体参见样例输出。

Sample Input

3 4 5 6

Sample Output

Case 1: 2 Case 2: 4 Case 3: 6
 
 
//刚开始我也是一点思路没有 但是渐渐的我觉得真应该是是个规律题
//手动模拟到8 就可以发现规律了   然后把公式变形一下  就出来代码的样子了
// Created by DELL on 2020/4/7.
//

#include <iostream>
#include <cstdio>
#include <cmath>

using  namespace std;

int main(int argc,char* argv[]) {
    int kase = 0,n,T; scanf("%d",&T);
    long long Ans = 0;
    while(T--) {
        scanf("%d",&n);
        Ans = 0;
        if(n & 1) { Ans = (n >> 1) * ((n >> 1) - 1) + (n >> 1); }
        else { Ans = ((n - 1 >> 1) + 1) * ((n - 1) >> 1); }
        printf("Case %d: %lld",++kase,Ans);
        if(T) printf("\n");
    }

    return 0;
}
 
 

1581: Average Number

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 351  Solved: 90
[Submit][Status]

Description

Please calculate the average number of the given n numbers without doing calculations of addition, multiplication, or division, or using any library fuction which is not in "stdio.h". It is guaranteed that the results are all integers and they are not less than 1 and not bigger than 100.

Input

The first line of the input contains a single integer T, indicating the number of the test cases, one per line.

Each test case starts with an integer n(1 ≤ n ≤ 200), followed by n numbers to calculate the average number. All numbers are within the range of [1, 100].

Output

For each test case, output the average number, one per line.

Sample Input

1 7 46 93 49 70 66 69 20

Sample Output

59

HINT

If any character of "+", "*", "/" or any name of library fuction which is not in "stdio.h" appers in your code, you will get "Invalid Word" and your code will not be accepted.

// 加乘除 用不了 就干脆全用减法    下面这句Created by Dell居然也是屏蔽字
// Created by DELL on 2020/4/7.
//
#include <cstdio>
#define  Maxn 202
using namespace std;
int a[Maxn];
int main(int argc,char* argv[]) {
    int T,n; scanf("%d",&T);
    while(T--) {
        scanf("%d",&n);
        for(int i=n; i>=1; i--) scanf("%d",&a[i]);
        for(int i=100; i>=1; i--) {
            long long Sum = i;
            for(int j=n; j>=2; j--) Sum -= i * (-1);
            for(int j=n; j>=1; j--) Sum -= a[j];
            if(Sum == 0) { printf("%d\n",i); break;}
        }
    }
    return 0;
}

 

 

  1600: New Sort I

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 240  Solved: 57
[Submit][Status]

Description

给定一个数列,请对这个数列重新排序,得到数列a[0],a[1]...a[n-1].

使a[0]为数列的最小值,a[1]为最大值,a[2]为次小值,a[4]为次大值...依次类推。

Input

对于每组数据,第一行首先输入一个n(0<n<=100000),第二行是数列的n个元素

输入的所有数字均在int的范围内。

Output

对每组数据中的n个元素重新排序后输出。

要求每相邻两个数字之间用空格隔开。

每两组相邻数据之间输出一个空行。

Sample Input

5 1 2 3 4 5 3 3 2 1

Sample Output

1 5 2 4 3 1 3 2

//
// Created by DELL on 2020/4/7.
//

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define Maxn 100005
using namespace std;
int a[Maxn];
int main(int argc,char* argv[]) {
	//freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    int n,opt = 0;
    while(scanf("%d",&n) == 1) {
        for(int i=1; i<=n; i++) scanf("%d",&a[i]);
        sort(a + 1,a +  n + 1);
        if(opt != 0) printf("\n");
        opt = 1;
        int p = 1,q = n;
        if(n == 1) {
        	printf("%d\n",a[1]);
        	continue;
		}
        for(int i=1; i<=n/2-1; i++){
            printf("%d ",a[p++]);
            printf("%d ",a[q--]);
        }
        printf("%d",a[p]);
        printf(" %d",a[q]);
        if(n & 1) printf(" %d",a[n / 2 + 1]);
        printf("\n");
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_35776409/article/details/105365218
今日推荐