• LightOJ 1338 && 1387


    B - B
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

    Description

    In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:

    1. You can change some uppercase letters to lower case and vice versa.
    2. You can add/remove spaces freely.
    3. You can permute the letters.

    And if two names match exactly, then you can say that one name is hidden into another.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with two lines. Each line contains a name consists of upper/lower case English letters and spaces. You can assume that the length of any name is between 1 and 100 (inclusive).

    Output

    For each case, print the case number and "Yes" if one name is hidden into another. Otherwise print "No".

    Sample Input

    3

    Tom Marvolo Riddle

    I am Lord Voldemort

    I am not Harry Potter

    Hi Pretty Roar to man

    Harry and Voldemort

    Tom and Jerry and Harry

    Sample Output

    Case 1: Yes

    Case 2: Yes

    Case 3: No

    判断第一个串是否包含第二个串,可以交换位置,改变大小写。。。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    template<typename T>
    bool is_lower(T x){
        if(x >= 'a' && x <= 'z')return true;
        return false;
    }
    template<typename T>
    void dispose(T *s){
        T *a;
        a = (T *)malloc(sizeof(s));
        int i, j;
        for(i = 0, j = 0; s[i]; i++){
            if(s[i] == ' ' || s[i] == '	')continue;
            a[j++] = is_lower(s[i]) ? s[i] : 'a' + s[i] - 'A';
        //    printf("%c %c
    ", s[i], a[j - 1]);
        }
        a[j] = 0;
        strcpy(s, a);
    }
    template<typename T>
    bool js(T *m, T *s){
        int i, j;
        for(i = 0, j = 0; m[i] && s[i]; i++){
            if(m[i] == s[j])j++;
        }
        if(s[j])return false;
        return true;
    }
    int main(){
        int T, kase = 0;
        scanf("%d", &T);
        char mstr[110], str[110];
        getchar();
        while(T--){
            gets(mstr);gets(str);
            dispose(mstr);dispose(str);
            sort(mstr, mstr + strlen(mstr));
            sort(str, str + strlen(str));
            if(js(mstr, str))
                printf("Case %d: Yes
    ", ++kase);
            else 
                printf("Case %d: No
    ", ++kase);
        }
        return 0;
    }
    1387 - Setu
    Time Limit: 2 second(s) Memory Limit: 32 MB

    Rahaduzzaman Setu, (Roll - 12) of 13th batch, CSE, University of Dhaka. He passed away on 18th April 2012. This is one of the saddest news to all. May he rest in peace. This problem is dedicated to him.

    This problem was written during his treatment. He will be in our prayers, always.

    "He has been suffering from Multi Drug Resistant TB for a long time. Now, his left lung is damaged and beyond repair. No medicine is working on his body to ease his pain. It is urgent to operate on his left lung so that the disease doesn't spread to his right lung. It can either be removed through surgery or transplanted. He comes from a modest family and it is difficult and impossible for them to bare his medical expenses anymore. Because of the money needed (12 million BDT) to transplant, it is his family's decision to go with the surgery (3 million BDT). We must help them financially by raising money. But we must not be confined with that amount only to do the surgery. We must go for the Transplant. Our target will be to collect as much as possible to help our friend [link]."

    However, in this problem, you have to build a software that can calculate the donations. Initially the total amount of money is 0 and in each time, two types of operations will be there.

    1)      "donate K" (100 ≤ K ≤ 105), then you have to add K to the account.

    2)      "report", report all the money currently in the account.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing an integer N (1 ≤ N ≤ 100) denoting the number of operations. Then there will be N lines each containing two types of operations as given. You may assume that the input follows the restrictions above. Initially the account is empty for each case.

    Output

    For each case, print the case number in a single line. Then for each "report" operation, print the total amount of money in the account in a single line.

    Sample Input

    Output for Sample Input

    2

    4

    donate 1000

    report

    donate 500

    report

    2

    donate 10000

    report

    Case 1:

    1000

    1500

    Case 2:

    10000

    题解:

    让做一个软件,记录当前账户余额;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    template<class T1, class T2>
    class Software{
        private:
            T1 *s;
            T2 money;
        public:
            Software();
            void Check();
            T2 Get();
            void Put(T1 *s, T2 money);
            ~Software();
    };
    template<class T1, class T2>
    Software<T1, T2>::Software():money(0){}
    template<class T1, class T2>
    void Software<T1, T2>::Put(T1 *s, T2 money = 0){
        this->s = (T1 *)malloc(sizeof(s));
        strcpy(this->s, s);
        this->money += money;
    }
    template<class T1, class T2>
    T2 Software<T1, T2>::Get(){
        return money;
    }
    template<class T1, class T2>
    void Software<T1, T2>::Check(){
        if(strcmp(this->s, "report") == 0)
            cout << Get() << endl;
    }
    template<class T1, class T2>
    Software<T1, T2>::~Software(){
        free(s);
    }
    int main(){
        int T, N, kase = 0;
        cin >> T;
        char s[15];
        long long money;
        while(T--){
            cin >> N;
            printf("Case %d:
    ", ++kase);
            Software<char, int>a;
            while(N--){
                cin >> s;
                if(s[0] == 'd'){
                    cin >> money;
                    a.Put(s, money);
                }
                else{
                    a.Put(s);
                }
                a.Check();
            }
        }
        return 0;
    }
    E - E
    Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

    Description

    You all probably know how to calculate the distance between two points in two dimensional cartesian plane. But in this problem you have to find the minimum arc distance between two points and they are on a circle centered at another point.

    You will be given the co-ordinates of the points A and B and co-ordinate of the center O. You just have to calculate the minimum arc distance between A and B. In the picture, you have to calculate the length of arc ACB. You can assume that A and B will always be on the circle centered atO.

     

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing six integers Ox, Oy, Ax, Ay, Bx, By where (Ox, Oy) indicates the co-ordinate of O(Ax, Ay) denote the co-ordinate of A and (Bx, By) denote the co-ordinate of B. All the integers will lie in the range [1, 10000].

    Output

    For each case, print the case number and the minimum arc distance. Errors less than 10-3 will be ignored.

    Sample Input

    5

    5711 3044 477 2186 3257 7746

    3233 31 3336 1489 1775 134

    453 4480 1137 6678 2395 5716

    8757 2995 4807 8660 2294 5429

    4439 4272 1366 8741 6820 9145

    Sample Output

    Case 1: 6641.81699183

    Case 2: 2295.92880

    Case 3: 1616.690325

    Case 4: 4155.64159340

    Case 5: 5732.01250253

    题解:求弧长长度:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    template<typename T>
    struct Point{
        T x, y;
        Point(T x = 0, T y = 0):x(x),y(y){}
        T getd(Point a, Point b){
            return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
        }
    };
    template<typename T>
    T getcos(T a, T b, T c){
        return (b*b + c*c - a*a) / (2*b*c);
    }
    int main(){
        int N, kase = 0;
        scanf("%d", &N);
        while(N--){
            Point<double>o, a, b;
            cin >> o.x >> o.y >> a.x >> a.y >> b.x >> b.y;
           // cout << "r = " << o.getd(o, a) << "   " << o.getd(o, b) << endl;
            double r = o.getd(o, a), d = o.getd(a, b);
            double coso = getcos(d, r, r);
            double O = acos(coso);
            double ans = O*r;
            printf("Case %d: %lf
    ", ++kase, ans);
        }
        return 0;
    }
    Area of a Parallelogram
    Time Limit: 1 second(s) Memory Limit: 32 MB

    A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:

     

    Fig: a parallelogram

    Now you are given the co ordinates of A, B and C, you have to find the coordinates of D and the area of the parallelogram. The orientation of ABCD should be same as in the picture.

    Input

    Input starts with an integer T (≤ 1000), denoting the number of test cases.

    Each case starts with a line containing six integers Ax, Ay, Bx, By, Cx, Cy where (Ax, Ay) denotes the coordinate of A,(Bx, By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range[-1000, 1000]. And you can assume that A, B and C will not be collinear.

    Output

    For each case, print the case number and three integers where the first two should be the coordinate of D and the third one should be the area of the parallelogram.

    Sample Input

    Output for Sample Input

    3

    0 0 10 0 10 10

    0 0 10 0 10 -20

    -12 -10 21 21 1 40

    Case 1: 0 10 100

    Case 2: 0 -20 200

    Case 3: -32 9 1247


    题解:找D,求面积。。。用java写了下,竟然wa。。。

    代码:

    package 随笔;
    
    import java.util.Scanner;
    
    
    
    class Point{
        static Scanner cin = new Scanner(System.in);
        public double x, y;
        public Point(){
            x = 0; y = 0;
        }
        public void Put(){
            x = cin.nextDouble();
            y = cin.nextDouble();
        //    System.out.println(x + " " + y);
        }
        public double Getd(Point a, Point b){
            return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
        }
        public double Getarea(double r1, double r2, double r3){
        //    System.out.println(r1 + " " + r2 + " " + r3);
            double r = (r1 + r2 + r3) / 2;
            return Math.sqrt(r * (r - r1) * (r - r2) * (r - r3));
        }
        public Point GetD(Point a, Point b, Point c){
            Point D = new Point();
            D.x = a.x + c.x - b.x;
            D.y = a.y + c.y - b.y;
            return D;
        }
    }
    
    public class AreaofaParallelogram {
        static Scanner cin = new Scanner(System.in);
        public static void main(String[] args){
            int kase = 0, N;
            N = cin.nextInt();
            while(N-- > 0){
                Point a = new Point();
                Point b = new Point();
                Point c = new Point();
                a.Put(); b.Put(); c.Put();
                double r1, r2, r3, area;
                r1 = a.Getd(a, b);
                r2 = a.Getd(a, c);
                r3 = a.Getd(b, c);
                area = a.Getarea(r1, r2, r3) * 2;
                Point D = new Point();
                D = a.GetD(a, b, c);
                //System.out.println("Case "+ (++kase) + ": " + " " + D.x + " " + D.y + " " + area);
                System.out.printf("Case %d: %.0f %.0f %.0f", ++kase, D.x, D.y, area);
                System.out.println();
            }
        }
    }
    Increase and Decrease
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:

    • he chooses two elements of the array ai, aj (i ≠ j);
    • he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 andaj = aj - 1.

    The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.

    Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.

    Input

    The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integersa1, a2, ..., an (|ai| ≤ 104) — the original array.

    Output

    Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

    Examples
    input
    2 2 1
    output
    1
    input
    3 1 4 1
    output
    3
    题解:+1 -1 也就是和能不能整除N能的话就是N,否则N- 1;
    jsva写的:
    import java.util.Scanner;
    
    
    public class Main {
        static Scanner cin = new Scanner(System.in);
        
        public static void main(String[] args){
            int N;
            while(cin.hasNext()){
                N = cin.nextInt();
                int sum = 0;
                for(int i = 0; i < N; i++){
                    sum += cin.nextInt();
                }
                if(sum % N == 0)
                    System.out.println(N);
                else
                    System.out.println(N - 1);
            }
        }
    }
  • 相关阅读:
    Java实现 LeetCode 679 24 点游戏(递归)
    Java实现 LeetCode 678 有效的括号字符串(暴力+思路转换)
    Java实现 LeetCode 678 有效的括号字符串(暴力+思路转换)
    Java实现 LeetCode 678 有效的括号字符串(暴力+思路转换)
    Java实现 LeetCode 677 键值映射(字典树)
    Java实现 LeetCode 677 键值映射(字典树)
    Java实现 LeetCode 677 键值映射(字典树)
    Java实现 LeetCode 676 实现一个魔法字典(暴力)
    PHP empty() 函数
    PHP floatval()、doubleval () 函数
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5452034.html
Copyright © 2020-2023  润新知