其他分享
首页 > 其他分享> > Codeforces Round #697 (Div. 3) F题 Unusual Matrix 和 G题 Strange Beauty

Codeforces Round #697 (Div. 3) F题 Unusual Matrix 和 G题 Strange Beauty

作者:互联网

F题:
此题考查位运算,同样是一道思维题。

//Dlove's template
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;
const int maxn = 1010;
string s[maxn];
string ss[maxn];

int main()
{
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		for(int i = 0;i<n;i++){
			cin >> s[i];
		}
		getchar();
		for(int i = 0;i<n;i++){
			cin >> ss[i];
		}
		for(int i = 0;i<n;i++){
			for(int j = 0;j<n;j++){
				int x = ss[i][j]-'0';
				int y = s[i][j]-'0';
				x ^= y;
				s[i][j] = char(x+'0');
			}
		}
		int flag = 0;
		int u = s[0][0]-'0';
		for(int i = 0;i<n;i++){
			for(int j = 0;j<n;j++){
				if((u+(s[i][j]-'0')+(s[0][j]-'0')+(s[i][0]-'0'))%2 == 1){
					flag = 1;
					break;
				}
			}
			if(flag == 1) break;
		}
		if(!flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
// prlong longf("%d\n", read() + read());
 return 0;
}

G题:
此题考查dp。

//Dlove's template
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define R register
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define Ls root << 1
#define Rs Ls | 1
#define sqr(_x) ((_x) * (_x))
#define Cmax(_a, _b) ((_a) < (_b) ? (_a) = (_b), 1 : 0)
#define Cmin(_a, _b) ((_a) > (_b) ? (_a) = (_b), 1 : 0)
#define Max(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define Min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define Abs(_x) (_x < 0 ? (-(_x)) : (_x))

using namespace std;

//#define getchar() (_S == _T && (_T = (_S =_B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? 0 : *_S++)
//char _B[1 << 15], *_S = _B, *_T = _B;

inline int read()
{
 R int a = 0, b = 1; R char c = getchar();
 for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
 for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
 return a * b;
}
inline ll lread()
{
 R ll a = 0, b = 1; R char c = getchar();
 for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
 for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
 return a * b;
}

const int maxn = 200010;
int a[maxn];
map<int,int> mp;
int dp[maxn] = {0};

int main()
{
	int t;
	cin >> t;
	while(t--){
		memset(dp,0,sizeof(dp));
		int n;
        n = read();
		for(int i = 0;i<n;i++){
			a[i] = read();
			mp[a[i]]++;
		}
		sort(a,a+n);
		for(int i = 1;i<maxn;i++){
			int x = i;
			if(!mp[x]) continue;
			dp[x] += mp[x];
			for(int j = 2;j*x<maxn;j++){
				dp[j*x] = max(dp[j*x],dp[x]);
			}
		}
		int sum = 0;
		for(int i = 0;i<n;i++){
			int x = a[i];
			sum = max(sum,dp[x]);
		}
		cout << n-sum << endl;
		mp.clear();
	}
// printf("%d\n", read() + read());
 return 0;
}

标签:Unusual,697,Beauty,int,long,getchar,include,dp,define
来源: https://blog.csdn.net/dinghanshengshi/article/details/113202061