CF Roubd #580(div2)前三题

1205A Almost Equal

找规律,n为奇数的时候可以,n为偶数的时候不行,分析一下样例每个元素的摆放位置就能找到规律。

        #include <stdio.h>
        #include <time.h>
        #include <string.h>
        #include <algorithm>
        #include <stack>
        #include <vector>
        #include <set>
        #include <iostream>
        #include <queue>
        #include <string>
        #include <math.h>
        typedef long long LL;
        using namespace std;
        const int inf = 0x3f3f3f3f;
        const int mod = 1e9 + 7;
        #define mid(l,r) (( l + r ) / 2)
        #define lowbit(x) (( x & ( - x )))
        #define lc(root) ((root * 2))
        #define rc(root) ((root * 2 + 1))
        #define me(array,x) (memset( array , x , sizeof( array ) ) )
        const int maxn = 1e6;
        LL a[maxn];
        int main()
        {
            int n,m,flag = 0;
            scanf("%d",&n);
            if(n%2==0)flag = 1;
            else {
                int s = 2;
                a[1] = 1 , a[2 * n] = 2 * n;
                for(int i = 2 , j = n + 1 ; i <= n ; i += 2 , j += 2){
                    a[j] = s++;
                    a[j+1] = s++;
                    a[i] = s++;
                    a[i+1] = s++;
                }
            }
            if(flag )printf("NO\n");
            else {
                printf("YES\n");
                for(int i=1;i <= 2*n;i++)
                printf("%d\n",a[i]);
            }
            return 0;
        }

1206A Choose Two Numbers

找最大的两个数就行了

    #include <stdio.h>
    #include <time.h>
    #include <string.h>
    #include <algorithm>
    #include <stack>
    #include <vector>
    #include <set>
    #include <iostream>
    #include <queue>
    #include <string>
    #include <math.h>
    typedef long long ll;
    using namespace std;
    const int inf = 0x3f3f3f3f;
    const int mod = 1e9 + 7;
    #define mid(l,r) (( l + r ) / 2)
    #define lowbit(x) (( x & ( - x )))
    #define lc(root) ((root * 2))
    #define rc(root) ((root * 2 + 1))
    #define me(array,x) (memset( array , x , sizeof( array ) ) )
    const int maxn = 1e3;
    int a[maxn],b[maxn];
    int main()
    {
        int n,m;
        scanf("%d",&n);
        for(int i = 0 ; i < n ; i++)scanf("%d",&a[i]);
        scanf("%d",&m);
        for(int i = 0 ; i < m ; i++)scanf("%d",&b[i]);
        sort(a,a+n);sort(b,b+m);
        printf("%d %d\n",a[n-1],b[m-1]);
        return 0;
    }

1206B Make Product Equal One

负数就直接变成-1,正数就变成1,注意0的个数,如果没有0且负数有奇数个,那就还需要把一个负数变成1

        #include <stdio.h>
        #include <time.h>
        #include <string.h>
        #include <algorithm>
        #include <stack>
        #include <vector>
        #include <set>
        #include <iostream>
        #include <queue>
        #include <string>
        #include <math.h>
        typedef long long LL;
        using namespace std;
        const int inf = 0x3f3f3f3f;
        const int mod = 1e9 + 7;
        #define mid(l,r) (( l + r ) / 2)
        #define lowbit(x) (( x & ( - x )))
        #define lc(root) ((root * 2))
        #define rc(root) ((root * 2 + 1))
        #define me(array,x) (memset( array , x , sizeof( array ) ) )
        const int maxn = 1e6;
        LL a[maxn];
        int main()
        {
            int n,m;
            scanf("%d",&n);
            LL ans = 0;
            int flag1 = 0 , flag2 = 0 ;
            for(int i = 1 ; i <= n ; i++){
                scanf("%lld",&a[i]);
                if(a[i] < 0 )flag1++;
                if(a[i] == 0)flag2++;
            }
            for(int i = 1 ; i <= n ; i++){
                LL x = a[i];
                if(x < 0)ans += ((-x)-1);
                if(x == 0)ans += 1;
                if(x > 0)ans += (x-1);
            }
            if(flag1 % 2 == 1 && flag2 == 0)ans += 2;
            printf("%lld\n",ans);
            return 0;
        }

B题第一次提交过了,手贱改了一下再交一次,还迷迷糊糊的还把pretest过了,最后主测试的时候就直接跳过了第一次的提交,然后第二次交的就wa了。。。。结束之后就试了一下第一次提交的对不对,结果是正确的。。。本来是可以出三个题的

发布了34 篇原创文章 · 获赞 7 · 访问量 1876

猜你喜欢

转载自blog.csdn.net/qq_43628761/article/details/99716380