Hunan University Programming Contest freshman season (Part II)

Then a part of


Problem H:Kuangyeye’s Game

题目描述:
    Christmas Day is coming! To celebrate this great festival, Kuangyeye, a creative boy, wants to play a game with everyone. The rule is described as following: there are several balloons in the classroom, and you have a prop gun. To achieve a higher goal, you need to shoot as many balloons as you can with one bullet. Now you have to judge whether you can explosive all balloons with one shoot. In a rigorous word, there are n points on the plane, you need to judge if they are on the same line. In addition, the balloons may extremely tiny, so some of them may share the same coordinate.
输入描述:
    The first line contains an integer n which indicates the number of balloons. The next n following lines contain two integers xi and yi each, which represent the X coordinate and the Y coordinate of i-th balloon respectively.
输出描述:
    If you can explosive all balloons with one shoot, output “Yes”. Output “No” otherwise(without quotes).
样例一:

Entry Export
2
1 1
-1 -1 Yes

Description: These two ballons are all on the line xy = 0.
Sample II:

Entry Export
3
1 2
2 1
3 3 No

说明:We can’t find a line which all these ballons on it.
备注1<=n<=1000, |xi|,|yi|<=1000。


Title effect:
for n points on a given plane, determines whether they are collinear.
The core ideas:

  • In the case of a point and two points must be collinear.
  • When greater than two points, we use tanA = tanB be calculated, then we know the first two points, tan = (y2-y1) / (x2-x1). We will x3, y3 by using the same equation is obtained, (y - y1) * (x2 - x1) - (y2 - y1) * (x - x1) = 0, then it is established (in this case without using the division, in order to avoid the denominator 0).
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    int x, y;
    int x1, y1, x2, y2;
    while (cin >> n)
    {
        if (n == 1)
        {
            cin >> x1 >> y1;
            cout << "Yes" << endl;
        }
        else if (n == 2)
        {
            cin >> x1 >> y1 >> x2 >> y2;
            cout << "Yes" << endl;
        }
        else if (n >= 3)
        {
            bool flag = 0;
            cin >> x1 >> y1 >> x2 >> y2;
            for (int i = 3; i <= n; i++)
            {
                cin >> x >> y;
                if ((y - y1) * (x2 - x1) != (y2 - y1) * (x - x1)) //标记为1则不成立
                    flag = 1;
            }
            if (flag)
                cout << "No" << endl;
            else
                cout << "Yes" << endl;
        }
    }
    return 0;
}

Problem I:Days passing

题目描述:
    LYX is the most handsome boy in HNU who likes math very much. One day his girlfriend JY asked LYX a simple problem: “Today is Sunday , what day of week will it be after 400^600 days, and what about 120^714?” LYX is very smart and answered: It will be Monday and Monday.
    Now LYX abstracts this problem as follows:
    ‘a’ denote the day of week today(‘a’ belong to {Mon, Tue, Wed, Thu, Fri, Sat, Sun}), what is the date after N^M (1<=N<10^10000,6<=M<10000) days ? Where M is exactly divided by 6.
输入描述:
    There is 1 line, 1 string, 2 integers,
    there are a, N and M, separated by a space.
输出描述:
    Output a string(Mon, Tue, Wed, Thu, Fri, Sat, Sun), the day of the week.
样例一:

Entry Export
Sun 2 12 Mon

Description:. The day (Sunday) after 2 ^ 12 (4,096) days will be Monday
Sample II:

Entry Export
Web 7 6 Web

Description: The day (Wednesday) after 7 ^ 6 (117,649) days will be Wednesday.
Sample III:

Entry Export
Thu 1 6 Fri

说明:The day(Thursday) after 1^6(1) days will be Friday.


Title effect:
gives the current week, N ^ M seeking days of the week.
The core ideas:

  • Due to restrictions (will burst long long) subject inputted to the high precision analog modulo operation.
  • String Analog modulo operation ALGORITHM: (a + b)% c = a% c + b% c.
//高精度取模运算
while(c=getchar())
{
   if(c==' ') break;
   N=(N*10+c-'0')%mod;//核心代码,也可用string来写读入
}

#include <bits/stdc++.h>
using namespace std;

int fastPow(int n, int m)
{
    int res = 1;
    int base = n;
    while (m)
    {
        if (m & 1)
            res = (res * base) % 7;
        base = (base * base) % 7;
        m >>= 1;
    }
    return res;
}
int main()
{
    string s1, day;
    string tmpday[8] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    int xx, m, n = 0, ans;
    cin >> day >> s1 >> m;
    for (int i = 0; i <= 6; i++)
        if (day == tmpday[i])
            xx = i;//当天是星期几?表示出来
    for (int i = 0; i < s1.length(); i++)
        n = (n * 10 + (s1[i] - '0')) % 7;
    n = fastPow(n, m);
    ans = (n + xx) % 7;
    cout << tmpday[ans] << endl;
    return 0;
}

Problem J:CET and miniskirt

题目概述:
    Xuxu is a student who likes English and skirt.Therefore, he has spent a lot of time preparing for CET. CET is a very important test, which determines the style of Xuxu’s skirt this year.
    Xuxu just finished the CET and got the standard answer after that. What’s more , if Xuxu gets zero, he will wear a skirt to the party, otherwise he will wear a suit(which is very disappointing). So Xuxu wants to know if it is possible for him to wear a skirt to the party. But unfortunately, he only remembers how many A, B, C and D he has written. Can you tell him weather he can wear a skirt in the party ?
输入描述:
    The first line contains an integer n which indicates the number of questions.
    The second line contain a string s which indicates the answer of each question.The answer only contain the upper case letters ‘A’,‘B’,‘C’ and ‘D’.
    The third line contain four integer a,b,c,d indicates the number of A,B,C,D Xuxu has written.
输出描述:
    If it’s impossible for Xuxu to wear skirt, output the minimum number of questions Xuxu may answer correctly, Otherwise output “orz”
样例一:

Entry Export
4
ABCD
1 1 1 1 barley

说明:
It’s possible to get a zero if Xuxu has written BADC in CET.
样例二:

Entry Export
3
AAA
2 1 0 0 2

说明:
It’s impossible to get a zero and the minium number of question Xuxu can answer correctly is 2.
备注:
n≤10^5,∣s∣=n,0≤a,b,c,d≤n,a+b+c+d=n。


Subject to the effect:
Conclusion: For all options, the number of options written <= the number of answers other options are set up, the lowest score of 0. Otherwise, there is a maximum number of options written> answer other option, then the minimum number of options written into this option - the answer to the other options.

Due to the limited level of this blogger, this problem is temporarily unable to AC, to avoid affecting the viewing audience to understand the effect of, the Bo Lord topic and people release solution to this problem, sorry.
The core ideas:
Here Insert Picture Description

#include <bits/stdc++.h>
using namespace std;
int a[4], b[4];
const int maxn = 1e5 + 50;
char s[maxn];
int main()
{
    int n;
    cin >> n;
    scanf("%s", s);
    assert(strlen(s) == n);
    for (int i = 0; i < n; ++i)
    {
        assert(s[i] >= 'A' && s[i] <= 'D');
        a[s[i] - 'A']++;
    }
    int ans = 0;
    for (int i = 0; i < 4; ++i)
    {
        cin >> b[i];
        assert(b[i] <= n && b[i] >= 0);
        if (n - a[i] < b[i])
            ans += b[i] + a[i] - n;
    }
    if (ans == 0)
        cout << "orz" << endl;
    else
        cout << ans << endl;
}


Problem K:Binbin’s treasure map

题目描述:
    Binbin is a clever boy who likes to wear a skirt. One day, he saw some beautiful skirts on Taobao, but he had not enough money, which made him sad.
    In order to make Binbin feel happy again, his’s friend Xu1024 gave him a treasure map. The treasure map is composed of three characters: ‘.’, ‘#’, ‘KaTeX parse error: Expected 'EOF', got '&' at position 4: '. &̲nbsp;&nbsp;&nbs…’ indicates that this position has 1 coin on it and is passablle.
    The locations outside the treasure map are all empty and passable.
    Binbin can move up, down, left, and right, but not at an angle.
    Firstly, Binbin can choose any grid as starting point.
    Because Binbin wanted to wear a skirt so much, he had a chance to teleport to a certain grid as another starting point.
    Binbin wanted to know how many coins he could eventually collect to buy skirts.
    Can you help him?
输入描述:
    The first line of each group contains two numbers N and M,(1<=N, M<=500), representing the number of rows and the number of columns of treasure map.
    Then there are next N lines, each line contains M characters. which describe the terasure map.
输出描述:
    Ouput a integer representingthe maxinum money Binbin would collected.
样例一:

输入 输出
4 4
. $ . $
.##.
#$#.
.#.# 3

说明:Binbin can start at point(1,1) so he can collect 2 coins.

Then Binbin can teleport to point(3,2) so he can collect 1 coin.

Finally, Binbin would collect 3 coins.

Published 13 original articles · won praise 18 · views 2841

Guess you like

Origin blog.csdn.net/acm_durante/article/details/103942943