Educational Codeforces Round 73题解

A.2048 Game

我们发现,我们可以忽略掉 2048 2048 2048以上的数,剩下的数开桶统计然后贪心即可.

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <vector>
#include <cstdlib>
#include <stack>
#define ll long long
#define pll std::pair<int,int>
#define mp std::make_pair
#define fi first
#define se second
#define oo 2147483647
#define PI 3.141592653590
#define rint register int
#define F(i,a,b) for(rint i=a;i<=b;i++)
#define D(i,a,b) for(rint i=a;i>=b;i--)

inline int _read () {int s = 0 , w = 1;char ch = getchar ();while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}return s * w;}
template < class T > inline void read ( T &x ) {T s = 0 , w = 1;char ch = getchar ();while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}x = s * w;return;}
template < class T , typename ...Argc > inline void read ( T &x , Argc &...Args ) {read ( x );read ( Args... );return;} 
template < class T > inline T max ( T x , T y ) {return x > y ? x : y;}
template < class T > inline T min ( T x , T y ) {return x < y ? x : y;}
template < class T > inline void abs ( T x ) {return x > 0 ? x : -x;}
template < typename T > void write ( T x ) {if ( x < 0 ) x = -x , putchar ( '-' );if ( x > 9 ) write ( x / 10 );putchar ( x % 10 + 48 );return;}
template < typename T > void writeln ( T x ) {write ( x ); printf ("\n"); }
template < class T > inline T gcd ( T x , T y ) {if ( x < y ) swap ( x , y );if ( !y ) return x;return gcd ( y , x % y );}
template < class T > inline T ksm ( T x , T y , T Mod ) {T tmp = 1;while ( y ) {if ( y % 2 == 1 ) tmp = ( tmp * x % Mod );x = ( x * x ) % Mod;y >>= 1;}return tmp;}	

/**********************************************************************************************************************************************************************************************************************************************************************/

const int N = 105;

int n; 
ll num[N];
int used[2050];

int main ( void ) {
	int T = _read ();
	while ( T-- ) {
		memset ( used , 0 , sizeof ( used ) );
		n = _read ();
		F ( i , 1 , n ) {
			num[i] = _read ();
			if ( num[i] <= 2048 )
				used[num[i]]++;
		}
		if ( used[2048] ) {
			puts ( "YES" );
			continue;
		}
		for ( int i = 1 ; i <= 1024 ; i *= 2 )
				used[i * 2] += ( used[i] / 2 );
		if ( used[2048] ) 
			puts ( "YES" );
		else 
			puts ( "NO" );
	}
	return 0;
}

B.Knights

我们贪心的考虑一下,如果我们现在这个位置的骑士,在它能移动的八个方向上,都会碰到其他的骑士,那么这个位置对答案的贡献一定是最优的.

结合样例,我们可以发现这样一种构造方法,我们从点 ( 1 , 1 ) (1,1) (1,1)开始进行一次 b f s bfs bfs,然后按照骑士的移动方法,每次更新一层,然后把这一层的骑士染色成和现在的骑士颜色不一样的颜色.

对于剩下的,那么可以证明没有任何点能跳到这个点,所以随便什么颜色都可以.

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <vector>
#include <cstdlib>
#include <stack>
#define ll long long
#define pll std::pair<int,int>
#define fi first
#define se second
#define oo 2147483647
#define PI 3.141592653590
#define rint register int
#define F(i,a,b) for(rint i=a;i<=b;i++)
#define D(i,a,b) for(rint i=a;i>=b;i--)

inline int _read () {int s = 0 , w = 1;char ch = getchar ();while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}return s * w;}
template < class T > inline void read ( T &x ) {T s = 0 , w = 1;char ch = getchar ();while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}x = s * w;return;}
template < class T , typename ...Argc > inline void read ( T &x , Argc &...Args ) {read ( x );read ( Args... );return;} 
template < class T > inline T max ( T x , T y ) {return x > y ? x : y;}
template < class T > inline T min ( T x , T y ) {return x < y ? x : y;}
template < class T > inline void abs ( T x ) {return x > 0 ? x : -x;}
template < typename T > void write ( T x ) {if ( x < 0 ) x = -x , putchar ( '-' );if ( x > 9 ) write ( x / 10 );putchar ( x % 10 + 48 );return;}
template < typename T > void writeln ( T x ) {write ( x ); printf ("\n"); }
template < class T > inline T gcd ( T x , T y ) {if ( x < y ) swap ( x , y );if ( !y ) return x;return gcd ( y , x % y );}
template < class T > inline T ksm ( T x , T y , T Mod ) {T tmp = 1;while ( y ) {if ( y % 2 == 1 ) tmp = ( tmp * x % Mod );x = ( x * x ) % Mod;y >>= 1;}return tmp;}	

/**********************************************************************************************************************************************************************************************************************************************************************/

int n;
char mp[105][105];

const int dx[] = { 0 , 1 , 1 , -1 , -1 , 2 , 2 , -2 , - 2 };
const int dy[] = { 0 , 2 , -2 , 2 , -2 , 1 , -1 , 1 , -1 };

void dfs ( int x , int y , char col ) {
	mp[x][y] = col;
	for ( int i = 1 ; i <= 8 ; i++ ) {
		int xx = x + dx[i];
		int yy = y + dy[i];
		if ( xx >= 1 && xx <= n && yy >= 1 && yy <= n && mp[xx][yy] != 'W' && mp[xx][yy] != 'B' ) 
			dfs ( xx , yy , col == 'W' ? 'B' : 'W' );
	}
	return;
}

int main ( void ) {
	n = _read ();
	dfs ( 1 , 1 , 'W' );
	bool flag = 1;
	for ( int i = 1 ; i <= n ; i++ ) {
		for ( int j = 1 ; j <= n ; j++ ) {
			if ( mp[i][j] == 'W' || mp[i][j] == 'B' ) 
				printf ("%c",mp[i][j]);
			else {
				printf ("%c" , flag?'B':'W');
				flag ^= 1;
			}
		}
		puts("");
	}
	return 0;
}
// Main Code
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值