ZOJ-3704 I am nexus master! Simulation

Source: Internet
Author: User

Question: there is a system for determining the user level. Different levels have different evaluation criteria. The current level is required to be given for a user's historical level and the latest data.

Solution: Map different levels of titles to numbers, or the number of historical levels, and then enumerate the numbers from the largest to the current number to check whether the upgrade is performed. If the upgrade is performed, a judgment is provided; otherwise, from the current level to the small number enumeration, check whether the downgrade is performed. You only need to determine whether the ratio is smaller than a threshold, because other conditions that meet the historical level must meet the level with a smaller number, the exit is determined if the score is not downgraded. Because peasant's judgment is different from others, it should be determined at the beginning.

The Code is as follows:

# Include <cstdlib> # include <cstdio> # include <cstring> # include <algorithm> # include <iostream> # include <map> # include <string> using namespace STD; const double EPS = 1e-8; struct user {char title [20]; int weeks; Double Down, up, ratio; void read () {scanf ("% S % d % lf", title, & weeks, & down, & UP); ratio = up/down;} void show () {puts (title) ;}void modify () ;}u; int wk [10] = {0, 0, 4, 8, 15, 25, 40, 60, 80,100}; int DN [10] = {0, 0, 50,120,300,500,750,102 4, 1536,307 2}; double Ru [10] = {0, 0, 1.05, 1.55, 2.05, 2.55, 3.05, 3.55, 4.05, 4.55}; double RD [10] = {0, 0, 0.95, 1.45, 1.95, 2.45, 2.95, 3.45, 3.95, 4.45 }; string STR [10] = {"Peasant", "user", "power_user", "elite_user", "crazy_user", "insane_user", "veteran_user", "extreme_user ", "ultimate_user", "nexus_master"}; Map <string, int> MP; in T Init () {for (INT I = 0; I <10; ++ I) {MP [STR [I] = I ;}} int sign (Double X, double Y) {If (x-y> EPS) return 1; else if (Y-x> EPS) Return-1; else return 0;} bool judge_peasant () {If (sign (U. down, 50)> = 0 & sign (U. ratio, 0.4) <0) return true; If (sign (U. down, 100)> = 0 & sign (U. ratio, 0.5) <0) return true; If (sign (U. down, 200)> = 0 & sign (U. ratio, 0.6) <0) return true; If (sign (U. Down, 400)> = 0 & sign (U. ratio, 0.7) <0) return true; If (sign (U. down, 800)> = 0 & sign (U. ratio, 0.8) <0) return true; return false;} bool upclass (int x) {If (U. weeks> = wk [x] & sign (U. down, DN [x])> = 0 & sign (U. ratio, Ru [x])> = 0) return true; return false;} bool dnclass (int x) {If (sign (U. ratio, RD [x]) <0) return true; return false;} void User: Modify () {If (judge_peasant () {strcpy (tit Le, STR [0]. c_str (); return;} int Rank = MP [title]; // obtain the current ranking for (INT I = 9; I> rank; -- I) {// first determine whether a higher level is obtained if (upclass (I) {strcpy (title, STR [I]. c_str (); Return ;}}for (INT I = rank; I> 1; -- I) {If (! Dnclass (I) {// exit the decision if this level can be kept;} else {// otherwise drop a level strcpy (title, STR [I-1]. c_str () ;}}/ * 3crazy_user 5000 5000 800.00 1000.00 crazy_user 15 1000.00 639.99veteran _ User 45 3000.00 insane _ User 45 */INT main () {int T; init (); For (scanf ("% d", & T); t --) {u. read (), U. modify (), U. show () ;}return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.