周末练习2

传送门:点击打开链接

F - F

Gym - 101778G

Ran Mouri and Sonoko Suzuki are preparing for the final exams. They decided to study mathematics as it is the hardest subject for them. While they are solving mathematical problems, they faced troubles with some questions, including the following question:

You are given a drawing for a sensor and some measurements about it. You have to find the rest of measurements. Sensor's design is as follow:

The data you have is the length of , the length of , the area of oda, and the area of obc. Your task is to calculate x and y, where x is the length of and y is the length of .

Can you help Ran and Sonoko Suzuki by solving this question?


Input

The first line contains an integer T (1 ≤ T ≤ 2 × 105), in which T is the number of test cases.

Then T lines follow, each line contains four integers k, l, m, and n (1 ≤ k, l, m, n ≤ 1012), in which k is the length of , l is the length of , m is the area of oda, and n is the area of obc.

Output

For each test case, print a single line containing two numbers x and y, where x is the length of and y is the length of . Your output will be considered correct if the absolute or relative error of every number in your output does not exceed 10 - 6.

Example
Input
1
18 16 72 288
Output
20 14

题意:给你一个图形,其中一些边和面积为已知,让你求两个位置的变量x,y;
思路:
关键是相到中学时期学的三角形相似,注意,相似比面积是边的平方,然后写出等式,一化简记得结果。注意使用scanf,否则TLE
代码:
#include <bits/stdc++.h>
using namespace std;
double k,l,m,n;
int main()
{
    //ios::sync_with_stdio(0);
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf",&k,&l,&m,&n);
        double q = sqrt(n)/sqrt(m);
        double y = l * q - k;
        double x = k * q - l;
        printf("%lf %lf\n",x,y);
    }
    return 0;
}

G - G

Gym - 101778H

Kojima Genta is one of the best friends of Conan, and the fattest one!

Everyone believes that Genta is just thinking about food. So, he wants to prove the opposite. So, his friends challenged him in a game. Genta's friends will give him a string s of length n, and m update operations. At each update operation, an integer p (1 ≤ p ≤ n) and a lowercase English letter c will be given to Genta, and he is asked to change the pth letter in the string s to the letter c.

Conan explained to Genta that an update operation is said to be beautiful if the string s was a palindrome string after the update operation has been executed.

Genta task is to count the number of beautiful update operations. Genta wants to win in this game no matter what this will cost because his friends promised him that the food will be at their expense throughout the week if he solved the task. Can you help Genta by solving his task?


Input

The first line contains an integer T (1 ≤ T ≤ 50), in which T is the number of test cases.

The first line of each test cases contains two integers n and m (1 ≤ n, m ≤ 105), in which n is the length of the string s and m is the number of update operations. The second line of each test cases contains a string s of length n consisting of lowercase English letters only. Then m lines follow, each line contains an integer p and a lowercase English letter c (1 ≤ p ≤ n), giving the update operations.

The sum of n and m overall test cases does not exceed 7 × 105 for each.

Output

For each test case, print a single line containing the number of beautiful update operations.

Example
Input
1
10 7
abcdefdcba
5 x
6 x
4 d
2 d
3 y
8 y
9 d
Output
3
Note

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar".

In the first test case, the string s will be updated as follow:

abcdefdcba abcdxfdcba abcdxxdcba abcdxxdcba adcdxxdcba adydxxdcba adydxxdyba adydxxdyda.

There are 3 beautiful update operations, which are the 2rd, 3th, and 7th operations.


题意:字符串操作问题,给你串字符串,让后进行一些操作,每个操作给出p(p位置)字符c(p位置替换为c),问你这些操作中有哪些能使得字符串成为回文串。
思路:
不能全部枚举,因为肯定会超时,最好的办法就是n/2,前n/2和后n/2进行比较,记录下相同的对数,然后每次替换完之后,先进行减,然后看替换完之后是否相同,若相同则在加,只要相同对数等于n/2,那么就是回文串,更新记录。
代码:
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
int n,m,p;
char c;
char s[100001];
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        cin>>(s+1);
        int cnt = 0 , ans = 0;
        for(int i = 1; i <= n/2; i++)
        {
            if(s[i]==s[n-i+1])
                cnt++;
        }
        for(int i = 1 ; i <= m ; i++)
        {
            cin>>p>>c;
            int opp = n - p + 1;
            if(s[p] == s[opp])
            {
                cnt--;
                s[p]=c;
                if(s[p] == s[opp]) cnt++;
            }
            else
            {
                s[p] = c;
                if(s[p] == s[opp]) cnt++;
            }
            if(cnt == n/2) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

H - H

Gym - 101778I

Conan is always busy investigating murders, and he rarely finds an opportunity to enjoy his time. His friend Ran told him that this lifestyle harms his health, and this may lead to premature death. So, Conan decided taking a break to enjoy his time.

At the night, Ran told Conan that he can enjoy by watching the UEFA Champions League matches. Conan does not know anything about this competition and its rules, so, Ran starts explaining to him what are the rules of the knockout stage that will start today.

In the knockout stage, two teams play two matches against each other, such that the first match will hold on first team's stadium and the second match will hold on second team's stadium. The winning team who will qualify for the next stage is the team who score more goals than its opponent. If the two teams score the same number of goals over the two matches, the team which scores more goals in the opponent stadium qualifies for the next stage. If this procedure does not produce a result (i.e. if both teams score the same number of goals at each other stadiums), two 15-minute periods of extra time are played at the end of the second match. (See notes for more clarification)

Ran is not sure if Conan understood her explanation or not, so she decides to give him a test. Ran will give Conan the results of two matches and he must determine the winner. Can you help Conan in his test so he can continue watching the match?


Input

The first line contains an integer T (1 ≤ T ≤ 500), in which T is the number of test cases.

Each test case consists of a line containing four integers a, b, c, and d (0 ≤ a, b, c, d ≤ 10), in which a is the number of goals the first team scored in the first match, b is the number of goals the second team scored in the first match, c is the number of goals the first team scored in the second match, and d is the number of goals the second team scored in the second match.

Output

For each test case, print a single line containing 1 if the first team won, 2 if the second team won, or  - 1 if the winner cannot be determined and the two teams will play an extra time.

Example
Input
3
1 2 4 1
4 0 1 6
2 0 0 2
Output
1
2
-1
Note

In the first test case, the aggregate score of the two matches is (First Team 5-3 Second Team). So, the first team won since it scored more goals.

In the second test case, the aggregate score of the two matches is (First Team 5-6 Second Team). So, the second team won since it scored more goals.

In the third test case, the aggregate score of the two matches is (First Team 2-2 Second Team). The two teams will play the extra time since the winner cannot be determined.


题意:
类似足球的主客场。进球数相同看谁客场的进球数多,若相同输出-1
思路:
水题,直接模拟就好
代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d;
        int sum1=0,sum2=0;
        cin>>a>>b>>c>>d;
        sum1 = a+c;
        sum2 = b+d;
        if(sum1>sum2)
        {
            cout<<"1"<<endl;
        }
        else if(sum1<sum2)
        {
            cout<<"2"<<endl;
        }
        else if(sum1 == sum2)
        {
            if(b>c)
            {
                cout<<"2"<<endl;
            }
            else if(c>b)
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"-1"<<endl;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_37668729/article/details/80303078