Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

0ms,用了一堆stl,数据弱的很啊,vector王记清零嚷昂2次醉了。。。

Posted by KatrineYang at 2016-09-15 12:36:55 on Problem 1333
#include <iostream>
#include <stdio.h>
#include <bitset>
#include <vector>
using namespace std;

struct cond{
	int type;//只取2,3,4
	int subtype;//只对type=3有效
	int sibNo1, sibNo2;
	bitset<1001> constBit;
};

bitset<1001> bs[110];

vector<cond> conds[110];

int n,m;

void init(){
	for(int i = 1; i <= m; i++) bs[i].reset();
	for(int i = 1; i <= m; i++) conds[i].clear();
}

int main() {
	int t;
	scanf("%d", &t);
	for(int ii = 0; ii < t; ii++){
		scanf("%d%d", &n, &m);
		init();
		for(int chd = 1; chd <= m; chd++){
			int id, gs;
			scanf("%d%d", &id, &gs);
			for(int j = 0; j < gs; j++){
				int type;
				scanf("%d", &type);
				switch(type){
					case -1:{
						int ggs;
						scanf("%d", &ggs);
						bitset<1001> tempBs;
						tempBs.reset();
						for(int k = 0; k < ggs; k++){
							int temp;
							scanf("%d", &temp);
							tempBs.set(temp);
						}
						bs[id] |= tempBs;
						break;
					}
					case -2:{
						cond tmpc;
						tmpc.type = 2;
						int sib;
						scanf("%d", &sib);
						tmpc.sibNo1 = sib;
						conds[id].push_back(tmpc);
						break;
					}
					case -3:{
						bitset<1001> b[2];
						b[0].reset(), b[1].reset();
						int sibs[2];
						int numB = 0, numS = 0;
						int tag;
						scanf("%d", &tag);
						if(tag == -1){
							numB++;
							int gss;
							scanf("%d", &gss);
							for(int k = 0; k < gss; k++){
								int tmmp;
								scanf("%d", &tmmp);
								b[0].set(tmmp);
							}
						}
						else{
							numS++;
							scanf("%d", &sibs[0]);
						}
						scanf("%d", &tag);
						if(tag == -1){
							int gss;
							scanf("%d", &gss);
							for(int k = 0; k < gss; k++){
								int tmmp;
								scanf("%d", &tmmp);
								b[numB].set(tmmp);
							}
							numB++;
						}
						else{
							scanf("%d", &sibs[numS]);
							numS++;
						}
						if(numB == 2){
							bs[id] |= (b[0] & b[1]);
						}
						else{
							cond tmpc;
							tmpc.type = 3;
							if(numB == 1){
								tmpc.subtype = 0;
								tmpc.sibNo1 = sibs[0];
								tmpc.constBit = b[0];
							}
							else{
								tmpc.subtype = 1;
								tmpc.sibNo1 = sibs[0];
								tmpc.sibNo2 = sibs[1];
							}
							conds[id].push_back(tmpc);
						}
						break;
					}
					case -4:{
						int fei, sib;
						scanf("%d%d", &fei, &sib);
						cond tmpc;
						tmpc.constBit.reset();
						for(int jj = 1; jj <= n; jj++) tmpc.constBit.set(jj);
						tmpc.type = 4;
						tmpc.sibNo1 = sib;
						scanf("%d%d", &fei, &sib);
						for(int k = 0; k < sib; k++){
							int tp;
							scanf("%d", &tp);
							tmpc.constBit.reset(tp);
						}
						conds[id].push_back(tmpc);
						break;
					}
					default:
						break;
				}
			}
		}
		while(1){
			bool gb = 0;
			for(int i = 1; i <= m; i++){
				bitset<1001> btemp = bs[i];
				int sz = conds[i].size();
				for(int j = 0; j < sz; j++){
					cond &c = conds[i][j];
					if(c.type == 2) btemp |= bs[c.sibNo1];
					else if(c.type == 4) btemp |= (bs[c.sibNo1] & c.constBit);
					else if(c.subtype == 0) btemp |= (bs[c.sibNo1] & c.constBit);
					else btemp |= (bs[c.sibNo1] & bs[c.sibNo2]);
				}
				if(btemp.count() > bs[i].count()){
					gb = 1;
					bs[i] = btemp;
				}
			}
			if(!gb) break;
		}
		for(int i = 1; i <= m; i++){
			printf("%d", i);
			for(int j = 1; j <= n; j++){
				if(bs[i][j]) printf(" %d", j);
			}
			printf("\n");
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator