AtCoder Beginner Contest 117 解題報告


果然abc都是手速場。

倒序開的qwq。
D題因為忘記1e12二進制幾位上界爆了一發。

A - Entrance Examination

就是除一下就行了。。。
看樣例猜題意系列。

#include<cstdio>
#include<algorithm>
#include<cstring>
int main(){
	double t,x;
	scanf("%lf%lf",&t,&x);
	printf("%lf",t/x);
	return 0;
}

B - Polygon

他都把定理給你了。。。
你直接按他的意思模擬就好,數組都不用開

#include <bits/stdc++.h>

int main() {
	int n, sum = 0, mx = 0;
	scanf("%d", &n);
	for(int x, i = 1; i <= n; ++i) {
		scanf("%d", &x);
		sum += x;
		mx = std::max(mx, x);
	}
	if(mx < sum - mx) puts("Yes");
	else puts("No");
}

C - Streamline

直接貪心就好了。
我們把序列先排序然后差分一下。
顯然中間那些長的間隔我們不要走。
所以把間隔排序。
然后再間隔的右邊放一個棋子就好了。
也就是說前m大的間隔我們都不用走。這個想了挺久的。。。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

    #define in(a) a=read()
    #define out(a) write(a)
    #define outn(a) out(a),putchar('\n')

    #define I_int ll
    inline I_int read() {
        I_int x = 0 , f = 1 ; char c = getchar() ;
        while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
        while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
        return x * f ;
    }
    char F[ 200 ] ;
    inline void write( I_int x ) {
        if( x == 0 ) { putchar( '0' ) ; return ; }
        I_int tmp = x > 0 ? x : -x ;
        if( x < 0 ) putchar( '-' ) ;
        int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
    }
    #undef I_int

}
using namespace io ;

using namespace std ;

#define N 100010

int m = read(), n = read();
int a[N], f[N];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	for(int i = 1; i <= n; ++i) a[i] = read();
	sort(a + 1, a + n + 1);
	if(m >= n) return puts("0"), 0;
	int cnt = 0;
	for(int i = 2; i <= n; ++i) {
		f[++cnt] = a[i] - a[i - 1];
	}
	sort(f + 1, f + n + 1, cmp);
	ll ans = 0;
	for(int i = m; i <= n; ++i) ans += f[i];
	printf("%lld\n", ans);
} 

D - XXOR

據說樣例鍋了?
反正我記錯位運算+上界算錯這題卡了半小時。。。
因為是XOR所以我們按位來考慮,從高位往低位貪心。
XOR是不進位的加法,我們從這個角度來考慮。
統計該位上0個數和1個數。
如果0的個數多顯然題面里的那個x這一位就必須有1(在x不超過k的情況下)。
注意開1ll,以及不要記錯取出一個數的第k位的位運算是長啥樣的。。。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

    #define in(a) a=read()
    #define out(a) write(a)
    #define outn(a) out(a),putchar('\n')

    #define I_int ll
    inline I_int read() {
        I_int x = 0 , f = 1 ; char c = getchar() ;
        while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
        while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
        return x * f ;
    }
    char F[ 200 ] ;
    inline void write( I_int x ) {
        if( x == 0 ) { putchar( '0' ) ; return ; }
        I_int tmp = x > 0 ? x : -x ;
        if( x < 0 ) putchar( '-' ) ;
        int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
    }
    #undef I_int

}
using namespace io ;

using namespace std ;

#define N 100010

ll n = read(), K = read();
ll a[N], cnt[2];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	for(int i = 1; i <= n; ++i) a[i] = read();
	ll ans = 0;
	for(ll k = 42; k >= 0; --k) {
		cnt[0] = cnt[1] = 0; 
		for(int i = 1; i <= n; ++i) {
			cnt[(a[i]>>k)&1ll]++;
		}
		if(cnt[0] > cnt[1] && ans + (1ll << k) <= K) ans += (1ll << k);
	}
	ll sum = 0;
	for(int i = 1; i <= n; ++i) {
		sum += ans ^ a[i];
	}
	printf("%lld\n", sum);
	return 0;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM