UPC 2020年秋季组队训练赛第十一场

问题 A: Divide the Cash
时间限制: 1 Sec 内存限制: 128 MB

题目描述
The UCF Programming Team coaches schedule practices regularly in fall and spring (by the way, all UCF students are welcome to the practices). During summer, the majority of the team members are gone but the coaches know how to make sure the students don’t get “rusty”. The
coaches usually give prize money and reward the team members based on how many problems they solve during summer. For example, let’s assume the coaches have $1,000 in prize money and there are three students. Let’s also assume the three students solve, respectively, 5, 8 and 7 problems, i.e., a total of 20 problems. So, the reward for one problem will be $50 ($1000/20) and the three team members will receive, respectively, $250, $400 and $350.

Given the total prize money and the number of problems each team member has solved, compute the reward for each student.

输入
The first input line contains two integers: n (1 ≤ n ≤ 30), indicating the number of team members and d (1 ≤ d ≤ 30,000), indicating the dollar amount to be divided among the students. Each of the next n input lines contains an integer (between 1 and 300, inclusive) indicating the number of
problems a team member has solved. Assume that the input values are such that the reward for one problem will be an integer number of dollars.
输出
Print the pay, in dollars, for each team member (in the same order as they appear in the input).

样例输入
3 1000
5
8
7
样例输出
250
400
350

解法:直接模拟…

问题 B: Sort by Frequency
时间限制: 1 Sec 内存限制: 128 MB

题目描述
We all have heard the expression “more is better” so, in this problem, we are going to give higher precedence to the letter occurring the most.

Given a string containing only lowercase letters, you are to sort the letters in the string such that the letter occurring the most appears first, then the letter occurring the second most, etc. If two or more letters occur the same number of times, they should appear in alphabetical order in the output.

输入
The input consists of a single string, appearing on a line by itself, starting in column 1 and not exceeding column 70. The input will contain only lowercase letters (at least one letter).
输出
Print the sorted version of the input string, all on one line with no spaces.

样例输入
dcbbdabb
样例输出
bbbbddac

题意一个长度不超过70的字符串,依次输出出现次数最多的字符,出现次数相同时,按照字典序输出。

做法1

#include <bits/stdc++.h>
#include <map>
using namespace std;
typedef pair<int, char> PIC;

string s;
map<char, PIC> heap;

struct A {
    
    
    int a;    char b;
    bool operator< (const A &w) const {
    
    
        if(a!=w.a)  return a>w.a;
        return b<w.b;
    }
}f[26];

int main()
{
    
    
    cin >> s;
    
    for(int i=0; i<s.size(); i++)
	{
    
    
        f[s[i]-'a'].a++;
        f[s[i]-'a'].b = s[i];
    }
    
    sort(f, f+26);
    
    for(int i=0; i<26; i++)
      if(f[i].a) 
        for(int j=0; j<f[i].a; j++)  cout<<f[i].b;
          
    return 0;
}

做法2

#include <bits/stdc++.h>
using namespace std;
const int N=30;
string ch;
int vis[N];

struct node {
    
    
    int a,d;
    bool operator<(const node &t) {
    
    
        return d!=t.d?d>t.d:a<t.a;
    }
}s[N];

int main()
{
    
    
    cin>>ch;
    int k=0;
    for(int i=0; i<ch.size(); i++)
        vis[ch[i]-'a']++;
    
    for(int i=0; i<26; i++)
        if(vis[i]) s[++k]={
    
    i,vis[i]};
        
    sort(s+1,s+1+k);
    
    for(int i=1; i<=k; i++)
      for(int j=1; j<=s[i].d; j++)
        printf("%c",s[i].a+'a');
    
    return 0;
}

问题 C: Fitting on the Bed
时间限制: 1 Sec 内存限制: 128 MB

题目描述
Arup’s daughter, Anya, doesn’t like sleeping in a bed in the usual way. In particular, she is willing to put her head anywhere, and furthermore, she’s willing to lie in any direction. For the purposes of this problem, Anya, who is quite skinny, as she’s only at the fifth percentile in weight, will be modeled as a line segment with her head being one of the end points of the segment. The bed will be modeled as a rectangle with the bottom left corner with coordinates (0, 0), the top left corner with coordinates (0, L), where L is the length of the bed, and the top right corner with coordinates
(W, L), where W is the width of the bed. In the left diagram below, Anya’s head is near the top left corner and she’s sleeping completely sideways, off the bed - this corresponds to the first sample case. In the right diagram below, her head starts at a point a bit below where it starts in the first
diagram, but she’s sleeping at a diagonal, which allows her to fit on the bed!
在这里插入图片描述
Given the size of the bed, the location of Anya’s head, her height, and the angle in which her body is in relation to her head (here we use 0 degrees to indicate that her body is going straight to the right of her head and 90 degrees to indicate that her body is going above her head), determine if Anya is fully fitting within the bed or not. (Note: a normal sleeping position would be having your head near (W/2, L) with your body in the direction of 270 degrees.)

输入
The first line of input contains three positive integers: L (L ≤ 500), the length of the bed in centimeters, W (W ≤ 500), the width of the bed in centimeters, and H (H ≤ 200), Anya’s height in centimeters. The second line of input contains three non-negative integers: x (x ≤ W), the number of centimeters from the left side of the bed Anya’s head is, y (y ≤ L), the number of centimeters from the bottom of the bed Anya’s head is, and a (a ≤ 359), the angle in degrees Anya’s body is facing in relation to her head.
输出
On a line by itself, output “YES” (no quotes) if Anya completely fits on the bed, or “NO”, otherwise. Note: for all cases where Anya doesn’t fit on the bed, at least 1% of her body will be off the bed. She’s considered on the bed if part or all of her touches edges of the bed but none of her body extends off the bed.

样例输入
200 150 115
40 190 0
样例输出
NO

提示
In the sample case, Anya’s head is near the top of the bed 40 centimeters from the left end of the bed, but her body is veering completely to the right. Since there is only 110 cm to the right and Anya is 115 cm tall, 5 cm of her is off the bed.

最后一个样例卡常,用随机化过了。

#include <bits/stdc++.h>
using namespace std ;
#define ios ios::sync_with_stdio(false) ,cin.tie(0)
typedef long long ll ;
const double esp = 1e-3 , pi = acos(-1) ;
typedef pair<int , int> PII ;

int work()
{
    
    
   double L , W , H , x , y , a ;
   cin >> L >> W >> H ;
   cin >> x >> y >> a ;
   double p = 1.0 * a * pi / 180.0 ;
   double xx = x + H * cos(p) ;
   double yy = y + H * sin(p) ;
   if(xx > -esp && yy > -esp && xx < W + esp && yy < L + esp) return 0 * puts("YES") ;
   double xxx = x + 0.99 * H * cos(p) ;
   double yyy = y + 0.99 * H * sin(p) ;
   if(xxx > W + esp  || yyy > L + esp || xxx < - esp || yyy < - esp) return 0 * puts("NO") ;
   srand(time(0)) ;
   if(rand() % 2) puts("YES");
   return 0 * puts("NO");
}

int main()
{
    
    
   work() ;
   return 0 ;
}

猜你喜欢

转载自blog.csdn.net/Luoxiaobaia/article/details/108805508
UPC