July-August ACM Training First (number theory and computational geometry)

Source: Internet
Author: User
Tags stdin

This section is Rujia's "Algorithmic Competition Primer Classic" (first edition) Chapter III of Number theory and computational geometry, but do not need to use classical algorithms and templates to simulate the main

Title Link: Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=48182#overview

Topic Analysis:

a.uva575 Simple simulation gives you a number that allows you to find the answer to the conversion as required, except that the process of conversion is similar to the conversion of the transformation (it's really a way to tell you), but because it doesn't tell you the range of the input numbers, So it's better to read the membership by string (it's a conversion anyway)

b.uva550 Non-AC

C.UVA568 calculates the last non-zero of the factorial of a given integer, note that the last digit of each number cannot be recorded and then be recursive, because if you encounter 125*8 this requires a number of digits to go wrong, so open Java large number is a no-brain approach, or depending on the size of the input data each time you save the last number of bits is also possible (about 5, 6 bit, but it is best to open long long, or overflow), because you can roughly estimate the maximum number of bits of the multiplication, the other way is to save the number of 2 and 5 after each multiplication, This can also calculate the number of the end 0, in factorial when the 2 and 5 are removed on it.

d.uva408 give you a recursive formula and the first item, ask you whether the sequence of 0,1,2, ... MOD-1 are present. Feel free to give some number, and then hit the table to find if the input of the two number coprime, is good, vice versa is bad

E.uva350 to a recursive, to find the length of the circulation section, by the principle of the drawer can be the length of the circulation section is certainly not more than M, then open the number of groups run over, found the circulation section can be, note that the cycle section does not necessarily start from the first.

f.uva10061 A comparison of the pit, test instructions is to let you find the factorial of N in the B-system after the number and number of zero. Here the number can not be used sterling (the topic deliberately card precision), that can only be honest log accumulation. After the number of zero is actually equal to the factorial of n can be divided into a number of square B, the method is to B decomposition factorization, and then find the B of each factor and its exponent, so that the factorial of n can be divided into how many B, and then divide by its exponent is the answer. The author of this question initially is the largest power of the factor in B, found not (in inverse case everyone to lift).

g.uva10392 Bare Write decomposition factorization, no pit no difficulty.

H.uva10250 a so-called computational geometry, the problem is to give a pair of sides equal to the four-sided (that is, parallelogram), and then to the side of the square to the outside, give a set of edges of the 2 square of the center, let you ask for the other two square center. The method is to turn the two points around the midpoint to 90 degrees. (Of course, two points to coincide with the case)

i.uva579 gives you a time to find out the degree of the sharp angle that the hour and minute hands pinch. Notice the classification discussion, I here is divided into two categories: in the same half and not in the same half, respectively, to find the angle of the 0:00 hour, and then add or subtract operation

j.uva375 give a isosceles triangle the bottom and high, first draw a inscribed circle, and then draw with this triangle and inscribed circle are tangent circle, and so on, find out all the circle of circumference and. The only thing to be aware of is that you can't use the infinite-equal-sum formula (the radius of the inscribed circle that says the smallest in the title). Did you see that. Did you see that. )

k.uva10387 Non-AC

l.uva10112 gives coordinates of less than 15 points, and three points, so that they do not have any other points and the largest area. Method: Violent enumeration, because the number of points is less than or equal to 15, so casually how to do all the line. As for the positional relationship between the point and the triangle, you can use the following method: If the area of the triangle is equal to the sum of the area of the 3 triangles that the other point is connected to the vertex of the triangle, then this point is inside the triangle.


The following code is affixed to the AC section:

A.

#include <iostream> #include <stdio.h> #include <fstream> #include <iomanip> #include <cmath > #include <string> #include <string.h> #include <sstream> #include <cctype> #include < climits> #include <set> #include <map> #include <queue> #include <vector> #include < iterator> #include <algorithm> #include <stack> #include <functional>/*int type Max Int_max,
The short maximum value is short_max long long and the maximum value is long_long_max*///cout << "OK" << Endl;
#define _CLR (x) memset (x,0,sizeof (x)) using namespace Std;
const int INF = Int_max;
Const double EPS = 1e-8;
Const double EULER = 0.577215664901532860;
Const double PI = 3.1415926535897932384626;
Const double E = 2.71828182845904523536028;

typedef long Long LL;
	int main () {//freopen ("sample.in", "R", stdin);
	
	Freopen ("Sample.out", "w", stdout);
	string S;
	Cin >> S;
		while (s!= "0") {int res = 0,T = 1; for (int i = s.length () -1;i>=0;i--) {res+=t* (s[i]-' 0 ');
		t = (t+1) *2-1;
		} cout << res << Endl;
	Cin >> S;
    }//fclose (stdin); 
    Fclose (stdout);
return 0; }


C.

Import Java.util.Scanner;
Import Java.math.BigInteger;
public class Main {public
    static void Main (string[] args) {
        Scanner in = new Scanner (system.in);
        while (In.hasnext ())
        {
            int x = In.nextint ();
            if (x = = 0) 
            {
                System.out.println ("1");
                Continue;
            }
            BigInteger res = Biginteger.one;
            for (int i = 1;i<=x;i++)
                res = res.multiply (biginteger.valueof (i));
            String s = res.tostring ();
            int p = s.length ()-1;
            while (S.charat (p) = = ' 0 ')
            {
                p--;
            }
            System.out.printf ("%5d", x);
            System.out.println ("-A" +s

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.