Focusing on old business, poj starts question ~

Source: Internet
Author: User

Poj hasn't done yet. Today, I happened to see Netease have a topcoder programming competition. In a few days, I entered the competition. I quickly reported a name and couldn't get a T-shirt.

I am also a trainer ~ Today, I took some time to do two weak poj questions and slowly recovered the feeling of ing.

 

It is found that using C ++ is better than using pure C in school, and STL is very powerful.

Questions A will be played in the future ~

 

 

1003 enumeration: a typical Mr is a table, and then the data is queried. Table O (n) Table O (1)

Question:

How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table .) with two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2+1/3=5/6 card lengths. In general you can makeNCards overhang by 1/2+1/3+1/4+...+1 /(N +1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, Etc ., and the bottom card overhangs the table by 1 /(N +1). This is already strated in the figure below.

 

Sample Input

1.003.710.045.190.00

Sample output

3 card(s)61 card(s)1 card(s)273 card(s)
Code
#include <iostream>using namespace std;int main(){float r[1000] = {0};r[1] = 0.5;for(int i=2;i<1000;i++){float s = i;float tmp = 1/(s+1);r[i] = r[i-1] + tmp;}float n;while(cin>>n){if( n == 0)break;for(int i=0;i<999;i++){if( r[i] < n && r[i+1] >=n ){cout<<i+1<<" card(s)"<<endl;break;}}}return 0;}
1006 enumeration is a primary school math problem, and O (n) is over:
There are three physiological cycles in life: physical strength, emotional strength, and mental strength. The cycle is 23 days, 28 days, and 33 days.
One day in each cycle is the peak. On the peak day, people will do well in the corresponding aspects. For example, at the peak of the intelligence cycle, people will be agile, and their energy is easy to concentrate.
Because the perimeter of the three cycles is different, the peaks of the three cycles usually do not fall on the same day. For everyone, we want to know when three peaks fall on the same day.
For each cycle, we will give the number of days from the first day of the current year to the peak (not necessarily the first peak time ).
Your task is to specify the number of days from the first day of the year, and the output of the next three peaks from the specified time (not including the specified time) falls on the same day.
(The number of days from the specified time ). For example, if the given time is 10 and the time of three peaks in the same day is 12 next time, 2 is output (note that this is not 3 ).

Sample Input

0 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 301 203 40-1 -1 -1 -1

Sample output

Case 1: the next triple peak occurs in 21252 days.Case 2: the next triple peak occurs in 21152 days.Case 3: the next triple peak occurs in 19575 days.Case 4: the next triple peak occurs in 16994 days.Case 5: the next triple peak occurs in 8910 days.Case 6: the next triple peak occurs in 10789 days.
#include<iostream> #include<stdio.h>#define MAXN 21252using namespace std;int main(){int a,b,c,d;int count=1;while( cin>>a>>b>>c>>d ){if( a == -1)break;int r = 1;while( r<=MAXN ){if( (r+d-c)%33==0 &&((r+d-b)%28==0) &&((r+d-a)%23==0)){cout<<"Case "<<count<<": the next triple peak occurs in "<<r<<" days."<<endl;break;}r++;}count++;}return 0;}
1002 hash table, with insufficient static memory (millions). I use STL map to automatically sort keys, which is so nice that even sorting is saved..
Bottleneck occurs when the hash table O (nlogn) is generated. The actual structure of map is a binary tree, And logn is automatically sorted during generation.
Enterprises like to use phone numbers that are easy to remember. One way to make phone numbers easy to remember is to write them into words or phrases that are easy to remember. For example, you can call tut-glop when calling the University of Waterloo. Sometimes, only some numbers in the phone number are spelled into words. When you return to the hotel in the evening, you can call 310-gino to order a pizza for Gino's. Another way to make phone numbers easy to remember is to group numbers in a memorable way. Call the "three dozen" numbers of Pizza Hut 3-10-10-10, you can order pizza from them.

The standard telephone number format is a seven-digit decimal number with a connector between the third and fourth digits. The dial number provides a ing from letters to numbers. The ing relationships are as follows:
A, B, and C are mapped to 2.
Map D, E, and F to 3
G, H, and I are mapped to 4
J, k, and l are mapped to 5.
M, N, and O are mapped to 6.
P, R, and s are mapped to 7
T, U, and V are mapped to 8
W, X, and Y are mapped to 9.

Q and Z are not mapped to any number, and do not need to dial connections. They can be added or deleted at will. The standard format of Tut-glop is 888-4567,310-Gino. the standard format of 3-10-10-10 is 310-310.

If the two numbers have the same standard format, they are equivalent (the same dialing)

Your company is compiling a telephone number book for a local company. As part of quality control, you want to check whether two or more companies have the same phone number.

Input

The input format is: the first line is a positive integer that specifies the number (up to 100000) in the phone number book ). The remaining line is a phone number. Each phone number consists of numbers, uppercase letters (except Q and Z), and connectors. Each phone number contains only seven digits or letters.

Output

Generates a line of output for each duplicate number. The output is the standard format of the number followed by a space and the number of duplicates. If multiple duplicate numbers exist, they are output in ascending order according to the number dictionary. If no duplicate numbers exist in the input data, output one line:
No duplicates.

Sample Input

 

124873279ITS-EASY888-45673-10-10-10888-GLOPTUT-GLOP967-11-11310-GINOF101010888-1200-4-8-7-3-2-7-9-487-3279

Sample output

310-1010 2
487-3279 4
888-4567 3

#include<iostream>#include<string>#include<map>using namespace std;#define MAXN 1000000long prase( string k ){long r = MAXN;long result = 0;for(long i=0;i<k.length();i++){if( k[i]>='0' && k[i]<='9'){long s = k[i] - '0';result += s*r;r = r/10;}if( k[i]>='A' && k[i]<='Y' ){long s;if(k[i]=='Q')continue;if( k[i] == 'A' || k[i] == 'B' || k[i] == 'C' )s=2;if( k[i] == 'D' || k[i] == 'E' || k[i] == 'F' )s=3;if( k[i] == 'G' || k[i] == 'H' || k[i] == 'I' )s=4;if( k[i] == 'J' || k[i] == 'K' || k[i] == 'L' )s=5;if( k[i] == 'M' || k[i] == 'N' || k[i] == 'O' )s=6;if( k[i] == 'P' || k[i] == 'R' || k[i] == 'S' )s=7;if( k[i] == 'T' || k[i] == 'U' || k[i] == 'V' )s=8;if( k[i] == 'W' || k[i] == 'X' || k[i] == 'Y' )s=9;result += s*r;r = r/10;}}return result;}int main(){map<long,long> hash;long n;cin>>n;for(long i=0;i<n;i++){string tmp;cin>>tmp;long code = prase(tmp);map<long,long>::iterator found = hash.find( code ); if ( found != hash.end() ){hash[code]++;}else{hash[code]=1;}}bool flag = false;for(map<long,long>::iterator iter = hash.begin(); iter != hash.end(); ++iter ){if( iter->second > 1){long head = iter->first/10000;long cut = iter->first%10000;printf("%.3ld-%.4ld %ld/n",head,cut,iter->second);flag = true;}}if(!flag)cout<<"No duplicates."<<endl;return 0;}
Related Article

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.