POJ 2453 An Easy Problem G++

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/woniupengpeng/article/details/78230689

#include <iostream>
#include <bitset>
#include <vector>
using namespace std;
int main()
{
	vector<int> jg;
	while(1)
	{
		bitset<21> foo;
		long long a;
		cin>>a;
		if(a==0)
		{
			break;
		}
		foo=a;
		int j=0;
		for(int i=0;i<21;i++)
		{
			if((foo[i]==1)&&(foo[i+1]==0))
			{
				foo[i+1]=1;
				foo[i]=0;
				break;
			}else if((foo[i]==1)&&(foo[i+1]==1))
			{
				foo[i]=0;
				foo[j]=1;
				j++;			
			}
		}
		a=0;
	 	long long b=1; 
		for(int i=0;i<21;i++)
		{
			a=a+foo[i]*b;
			b=b*2;
		} 
		jg.push_back(a);
	}
	for(int i=0;i<jg.size();i++)
	{
		cout<<jg[i]<<endl;
	}
	return 0;
} 

求在二进制中和给出数 1 同样多,且比给出数大的最小数。


展开阅读全文

Another Easy Problem

09-05

Problem DescriptionnNowadays, many universities no longer force students to follow a fixed curriculum; instead they allow students to choose the courses on an individual basis. However, new programs need to be written to satisfy such needs. Your job is to write such a program.nIn our system, the following objects exist: Time Period, Course and Student. The relationships between the three objects are as follows:nA course has a capacity, and is associated with multiple time periods; a student can register for multiple courses in the system (resulting in a possibly conflicting schedule).nTo resolve possible conflicts with the schedules as well as to ensure that the number of students registered for each course does not exceed its capacity, the system will use the logic described below to determine the result: nProcess courses, in the order they appear in the input.nFor each course: Check each student's request in the order it is received, and reject the request if a) accepting the request will result in a conflict in the student's schedule, or b) if no more students could be accepted by this class, or c) the student has already enrolled in this class; otherwise, the request is accepted.nnCan you solve this easy problem?n nnInputnThere are multiple test cases in the input file. nEach test case starts with three integers, N, M and R (1 <= N <= 20, 1 <= M <= 20, 0 <= R <= N * M), the number of students, the number of courses, and the number of requests, respectively.nEach of the following N lines contains one string, the ID of the student. The ID will contain no characters other than '0'...'9' The next part of each test case consists of M lines, each of which contains three integers, I, C, T, (C <= 100, T <= 30), the ID of the course, the capacity, and the number of time periods used by the course respectively; T more integers follows, representing the unique identifiers of the time periods. The description for the requests comes next, each line in the format of [Student ID](Space character)[Course ID], in the order as the requests are received. It is guaranteed that the requests are always valid, i.e., both the student ID and the course ID could be found in the description given above.nTwo consecutive test cases are separated by a blank line. Input ends with End-of-File.n nnOutputnFor each test case, print the total number of requests accepted by the system, in the format as indicated in the sample output. n nnSample Inputn2 2 4n0n1n101 1 2 3 4n102 2 1 5n0 101n1 102n1 101n0 102nn1 1 0n4n5 1 1 5n nnSample OutputnCase 1: 3nCase 2: 0 问答

An Easy Problem for Elfness

09-28

Problem DescriptionnPfctgeorge is totally a tall rich and handsome guy. He plans to build a huge water transmission network that covers the whole southwest China. To save the fund, there will be exactly one path between two cities.nnSince the water every city provides and costs every day is different, he needs to transfer water from one particular city to another as much as possible in the next few days. However the pipes which connect the cities have a limited capacity for transmission. (Which means the water that transfer though the pipe should not exceed a particular amount) So he has to know the maximum water that the network can transfer in the next few days.nnHe thought it's a maximum flow problem, so he invites an expert in this field, Elfness (Also known as Xinhang senior sister) to help him figure it out.nnUnlike Pfctgeorge, Elfness quickly finds that this problem is much easier than a normal maximum flow problem, and is willing to help Pfctgeorge.nn"Oh well, this problem is not a tough one. We can ..."nnAbruptly, Pfctgeorge's iPhone rings, and ... the ringtone is Mo Di Da Biao Ke.nn"You can make that? Excellent! "Pfctgeorge hangs up his iPhone, and turns to Elfness.nn"Here's good news for you. A construction team told me that every pipe's capacity can be extended for one day. And the price for extending one unit capacity varies from day to day. "nn"Eh well, that's a good news for you, not me. Now it's rather like a minimum cost ow problem, right? But it's still not a tough one, let me have a think. "nnAfter a few seconds' thought, Elfness comes up with a simple solution.nn"Ok, we can solve it like... "nnAbruptly, here comes Mo Di Da Biao Ke again.nn"Seriously? You can build new pipes? Thank you very much. "nn"OK, my dear Elfness, we got more good news. Another construction team said they can build one or more pipes between any two cities and their pipes are exactly like the original ones except that they only work for one day. And the capacity of the new pipes is only one, but they can be extended, too. Of course, their price to build a single pipe also varies in days. "nn"You mean the new pipes can be extended too? Wow, things are getting more interesting. Give me a few minutes. "nnElfness takes out his new ultrabook which is awarded in VK cup and does some basic calculation.nn"I get it. The problem can be solved ..."nnMo Di Da Biao Ke again, but this time it's from Elfness's phone.nn"As you see, I have to go out. But I know someone else who can also solve this; I'll recommend this guy for you. "nnAnd of course, that poor guy is YOU. Help Pfctgeorge solve his problem, and then the favorability about you from Elfness will raise a lot.n nnInputnThe first line has a number T (T <= 10) , indicating the number of test cases.nnThe first line of each test case is two integers N (1 <= N <= 100000) and M (1 <= M <= 100000), indicating the number of the city that the original network connects and the number of days when Pfctgeorge needs to know about the maximum water transmissions. Then next N - 1 lines each describe a pipe that connects two cities. The format will be like U, V , cap (1 <= U, V <= N and 0 <= cap < 10000), which means the ids of the two cities the pipe connects and the transmission limit of the pipe. As is said in description, the network that the cities and pipes form is a tree (an undirected acyclic graph).nnThen next M lines of the test case describe the information about the next few days. The format is like S, T, K, A, B(0 <= K <= 2^31 - 1, 1 <= A, B <= 2^31 - 1). S means the source of the water while T means the sink. K means the total budget in the day. A means the cost for a construction team to build a new pipe and B means the cost for a construction team to extend the capacity of a pipe.nnI am glad to list the information of building a new pipe and extending the capacity.nn1. Pfctgeorge can build a new pipe between any two cities, no matter they have been directly connected or not. Pfctgeorge can build more than one new pipe between any two cities.n2. The capacity of the pipe that was newly built is one.n3. Pfctgeorge can extend the capacity of any existed pipe including the newly built one and the original one.n4. Each time you extend the capacity of one pipe, the capacity of that pipe increases one.n5. The cost of building a new pipe is A and the cost of extending a pipe is B.n6. You can take any constructions in any times and the only limit is to make sure the total costs not exceed the budget.n7. All the work that construction team does only lasts one single day.n nnOutputnFor every case, you should output "Case #t:" at first, without quotes. The t is the case number starting from 1.nThen for each day, output the maximum water Pfctgeorge can transfer from S and T with a budget of K.n nnSample Inputn2n5 1n1 2 2n1 3 5n2 4 1n4 5 2n1 5 3 3 2n5 5n1 2 10n2 3 2n3 4 7n2 5 7n1 5 0 1 3n1 3 0 2 3n1 5 3 2 3n1 2 7 3 1n1 3 2 3 1n nnSample OutputnCase #1:n2nCase #2:n7n2n8n17n4 问答

没有更多推荐了,返回首页