NOIP2000 Popularization Group

[NOIP2000 Popularization Group T1] Improvement of calculator

NCL is a laboratory specializing in the improvement and upgrading of calculators. Recently, the laboratory received a task entrusted by a company: it is necessary to add the function of solving the unary linear equation to a model of the company. The laboratory handed this task to a newcomer Mr. ZL who had just entered. In order to accomplish this task well, Mr. ZL first studied some 
  examples of unary linear equations: 
  4 + 3x = 8 
  6a-5 + 1 = 2-2a 
  -5 + 12Y = 0 
  Mr. ZL was told by the supervisor that the calculator The one-degree linear equation typed above contains only integers, lowercase letters, and ten, one, and = three mathematical symbols (of course, the symbol "one" can be used as a minus sign or a negative sign). There are no parentheses or division signs in the equation, and the letters in the equation indicate the unknown. 
[Problem Solving] 
  Write a program that solves the input unary linear equation, and outputs the result of solving the equation (accurate to three decimal places) to the screen. You can assume that the judgment of the correctness of the typed equation is done by another programmer, or that the typed one-degree linear equations are all legal and have unique real number solutions.

The input file is only one line, a string, and the length does not exceed 100.

The output file is only one line and is the result of the equation.

I feel that this question is an analog question, there are many details to pay attention to, and there are also techniques, divide the number into constants and coefficients, use two numbers to simulate the left and right sides of the symbol and equation

#include <iostream> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
#include <stack> 
#include <cstdio> 
#include <queue> 
#include <map> 
#include <vector> 
#include <set> 
using namespace std; 
const int maxn = 1010; 
const int INF = 0x3fffffff; 
string s; 
// I only passed two sets of data for this simulation. . . . 
// read the solution to a problem we found good ideas are clear 
// weeping 
/ * 
int Change (the X-String) { 
	int OP = 0; 
	for (int i = 0; i <x.length (); i ++) OP = OP * 10 + (x [i]-'0'); 
	return op; 
} 
int vis [maxn] = {0}; 
* / 
int l, r; // l means coefficient, r means constant 
char x;
	int f1 = 1, f2 = 1, temp = 0; 
	// f1 indicates whether it is a negative number (negative number -1, positive number 1), f2 indicates whether it is on the left or right side of the equal sign, left 1, right -1 
	// the final result (Constant): temp * (-f2) * f1, the negative number on the right is positive, the negative number on the left is negative, temp stores temporary data 
	// coefficient: f1 * f2, the coefficient is placed on the right, so the negative on the right is Negative, positive on the left becomes negative 
	while (scanf ("% c", & c)! = EOF) {// According to the input one by one 
		if (c> = '0' && c <= '9') { 
			temp = temp * 10 ; 
			temp + = c-'0 '; 
		} 
		else { 
			if (c> =' a '&& c <=' z ') { 
			if (temp == 0) l + = f2 * f1; // The coefficient is 1 
			else l + = temp * f2 * f1; 
			x = c; 
		} 
		else r + = temp * (-f2) * f1; // Either a coefficient or a constant, the constant is (-f1) * f2 
		temp = 0; 
	} 
	if (c == '+ ') { 
		f1 = 1; continue; 
	} 
	else if (c =='-') { 
		f1 = -1; continue;// Indicates the coefficient 
	} 
	else if (c == '=') {
				= '9') { vis [j] = 1; 
			}

='9'){
				stemp+=s[j];
			temp=change(stemp);vis[j]=1; 
			if(s[j]=='-') temp=-temp;
			sumx+=temp;
		} 
		else if(s[i]=='=') flag=1;
		else if(flag==1&&(s[i]>='a'&&s[i]<='z')){
			j=i;
			vis[i]=1;
			string stemp;
			while(s[--j]>='0'&&s[j]<='9'){
				stemp+=s[j];
				vis[j]=1;
			}
			temp=change(stemp);vis[j]=1;
			if(s[j]=='+') temp=-temp;
			sumx+=temp; 
		}
	}
	flag=0;
	for(int i=1;i<=s.length();i++){
		if(s[i]=='=') flag=1;
		else if(s[i]>='0'&&s[i]<='9'&&vis[i]==0){
			j=i;
			string stemp;
			while(s[j]>='0'&&s[j]<='9'&&vis[j]==0) {
				stemp+=s[j];
				vis[j]=1;
				j++;
			}
			//cout<<"stre  "<<stemp<<endl;
			temp=change(stemp);
			//cout<<flag<<" "<<temp<<"  "<<s[i-1]<<endl;
			if(flag==0&&s[i-1]=='-') {
				temp=-temp;
			//	cout<<"zuo"<<temp<<endl;
			}
			else if(flag==1&&s[i-1]!='-') {
				temp=-temp;
				//cout<<"you"<<temp<<endl;
			}
			sumy+=temp;
		}
	}
	//for(int i=1;i<=s.length();i++) cout<<vis[i]<<" ";
	//cout<<endl;
	sumy=-sumy;
	//cout<<"zuo"<<temp<<endl;
	//cout<<sumx<<endl<<s<<endl<<-sumy<<endl;
	double res=double(sumy)/double(sumx);
	printf("%c=%.3lf\n",x,res);
	*/ 
return 0;
}

  

1215-【NOIP2000 Popularization Group T2】 Taxes and subsidies

The lower the price of each product, the corresponding increase in sales. It is now known that the cost of a certain commodity and its sales at several price points (the product will not be lower than the cost of sales), and assume that the change in sales between adjacent price points is linear and after the price is higher than the given maximum price, The sales volume decreases with a fixed value. (We assume that both the price and the sales volume are integers) 
  For some special commodities, it is impossible for the market to completely adjust their prices. At this time, the government needs to control it with taxes or subsidies. (The so-called tax or subsidy is to charge or give a fixed amount of money to the manufacturer for each product)
  Solution: You are a project manager of a consulting company, and now you already know the expected price of a certain commodity by the government, and in various Sales at the price point. You are required to determine whether the government is taxable or subsidized by the minimum amount (also an integer) of this product, so that the merchant can obtain the maximum total profit at such a price expected by the government relative to other prices.
  Total profit = unit product profit *
  unit sales  unit product profit = unit product price-unit product cost (-tax or + subsidy)

The first line of input is the expected price of the government for a certain commodity. The
  second line has two integers. The first integer is the cost of the commodity. The second integer is the sales volume at the cost price. The
  following lines have two in each line. Integers, the first is the unit price at a certain price, the second is the sales volume at this time, with a line of -1, -1 represents all known price points and the corresponding sales volume after the
  input is completed , the last line of the input is a single integer representation Outside the highest known unit price, every additional dollar will reduce sales.

There are two cases of output: If the maximum total profit can be obtained at the government's expected price, a single integer is output. The sign of the number indicates whether it is a subsidy or tax, and the size of the number indicates the minimum amount of subsidy or tax. If there are multiple solutions, take the output with the smallest absolute value. 
  If the maximum total profit cannot be obtained at the government's expected price, output "NO SOLUTION".

First read the topic first (I do n’t seem to understand TAT at all

 

Guess you like

Origin www.cnblogs.com/shirlybaby/p/12732838.html