不知道为什么错了 普及提高减
  • 板块学术版
  • 楼主xubotao1004
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/2/18 17:07
  • 上次更新2023/10/24 00:27:09
查看原帖
不知道为什么错了 普及提高减
562420
xubotao1004楼主2023/2/18 17:07

P8899 [USACO22DEC] Reverse Engineering B

#include <bits/stdc++.h>
using namespace std;

struct node{
	string str;
	int ans;
};

int a0[500],a1[500];

int main(){
	int t;
	cin>>t;
	
	while(t--){
		queue<node>q;
		int n,m;
		cin>>n>>m;
		
		for(int i = 1;i<=m;i++){
			node s;
			cin>>s.str>>s.ans;
			q.push({s.str,s.ans});
		}
		
		for(int i = n-1;i>=0;i--){
			memset(a0,0,sizeof a0);
			memset(a1,0,sizeof a1);
			int cnt0 = 0;
			int cnt1 = 0;
			for(int j = 1;j<=m;j++){
				node num = q.front();
				q.pop();
				if(num.str[i] == '0'){
					a0[++cnt0] = num.ans;
				}else{
					a1[++cnt1] = num.ans;
				}
				q.push(num);
			}
			int ch0 = a0[1];
			int ch1 = a1[1];
			int p0 = 1,p1 = 1;
			for(int j = 2;j<=cnt0;j++){
				if(a0[j]!=ch0){
					p0 = 0;
					break;
				}
			}
			for(int j = 2;j<=cnt1;j++){
				if(a1[j]!=ch1){
					p1 = 0;
					break;
				}
			}
			int ct = 0;
			for(int j = 1;j<=m;j++){
				node num = q.front();
				q.pop();
				if(p0 && num.str[i] == '0' || p1 && num.str[i] == '1'){
					++ct;
					continue;
				}else{
					q.push(num);
				}
			}
			m-=ct;
		}
		
		if(!q.empty()){
			int cc = 0;
			int x = q.front().ans;
			q.pop();
			while(!q.empty()){
				int t = q.front().ans;
				q.pop();
				if(t != x){
					cc = 1;
					break;
				}
			}
			if(cc) cout<<"LIE"<<endl;
			else{
				cout<<"OK"<<endl;
			}
		}
		else {
			cout<<"OK"<<endl;
		}
	}
	
	return 0;
}
2023/2/18 17:07
加载中...