2021年度训练联盟热身训练赛第三场赛后补题

A Circuit Math

题目描述
You are enrolled in the Computer Organization and Architecture course at your university. You decide to write a program to help check your work by computing the output value of a combinational digital circuit, given its inputs.

Consider the circuit shown in Figure A.1, which we use for illustration. This circuit has four inputs (letters A through D on the left), each of which is either true or false. There are four ‘gates’ each of which is one of three types: AND, OR, or NOT. Each gate produces either a true or false value, depending on its inputs. The last gate (the OR on the right) produces the output of the entire circuit. We can write these three types of gates in text by their equivalent logical operators: * for AND, + for OR, and - for NOT. In what follows, we’ll use the operators rather than gates to describe circuits.

Here is how these operators work. Given an assignment of true (T) or false (F) for each input, the operators produce the truth value indicated in the following tables:

Notice that AND and OR take two inputs, whereas NOT operates on only one input. Also, we use postfix notation to write expressions involving operators (like A B *), where the operator comes after its input(s) (just as how in Figure A.1, each gate in the circuit diagram comes after its inputs).

When we describe a valid circuit in postfix notation, we use the following syntax.

An uppercase letter (A through Z) is a valid circuit. In other words, an input alone (without any gates) is a valid circuit (which produces as output its own input value).
If and are valid circuits, then ’ *’ is a valid circuit that produces the AND of the outputs of the two subcircuits.
If and are valid circuits, then ’ +’ is a valid circuit that produces the OR of the outputs of the two subcircuits.
If is a valid circuit, then ’ -’ is a valid circuit that produces the NOT of 's output.

No other description is a valid circuit.

Thus, one of the ways the circuit in Figure A.1 could be described using postfix notation is as the string:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~A~ B~ * C D~ +~ -~ + A B ∗ C D + − +

Given a truth value (T or F) for each of the inputs (A, B, C, and D in this example), their values propagate through the gates of the circuit, and the truth value produced by the last gate is the output of the circuit. For example, when the above circuit is given inputs A = T, B = F, C = T, D = F, the output of the circuit is F.

Given an assignment to variables and a circuit description, your software should print the output of the circuit.

输入描述:
The first line of the input consists of a single integer nn, satisfying 1 \leq n \leq 261≤n≤26, denoting the number of input variables. Then follows a line with nn space-separated characters. Each character is either TT or FF, with the i-th such character indicating the truth value of the input that is labeled with the i-th letter of the alphabet.

The last line of input contains a circuit description, which obeys the syntax described above. Each circuit is valid, uses only the first nn letters of the alphabet as input labels, and contains at least 11 and at most 250250 total non-space characters.

Note that while each variable is provided only one truth value, a variable may appear multiple times in the circuit description and serve as input to more than one gate.

输出描述:
Print a single character, the output of the circuit (either TT or FF), when evaluated using the given input values.
示例1
输入
复制
4
T F T F
A B * C D + - +
输出
复制
F

【题目分析】

这就是一个简答的STL的站的应用,只要你能看懂题目,你就可以轻松付AC

【代码展示】

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>
typedef long long ll;
using namespace std;

map<int,map<int,int> >flag;

stack<bool> s;

int main()
{
    int n;
    int pos = 0;
    cin>>n;
    char ch = getchar();
    char a[100];
    char b[1000];
    cin.getline(a,100);
    cin.getline(b,1000);

    int lenb = strlen(b);
    for(int i=0;i<lenb;i++)
    {
        if(b[i]>='A' && b[i]<= 'Z')
        {
            if(a[pos] == 'T')
                s.push(1);
            else
                s.push(0);
            pos += 2;

        }
        else
        {
            if(b[i] == '*')
            {
                int t1,t2;
                t1 = s.top();
                s.pop();
                t2 = s.top();
                s.pop();
                if(t1==1&& t2==1)
                {
                    s.push(1);
                }
                else
                {
                    s.push(0);
                }
            }
            else if(b[i] == '+')
            {
                int t1,t2;
                t1 = s.top();
                s.pop();
                t2 = s.top();
                s.pop();
                if(t1 == 1 || t2 == 1)
                {
                    s.push(1);
                }
                else
                {
                    s.push(0);
                }
            }
            else if(b[i] == '-')
            {
                int t1 = s.top();
                s.pop();
                if(t1==1)
                {
                    s.push(0);
                }
                else
                {
                    s.push(1);
                }
            }

        }
    }

    int ans = s.top();
    if(ans)
        printf("T\n");
    else
        printf("F\n");

    return 0;
}


B Diagonal Cut

题目描述

Quido and Hugo are making a chocolate cake. The central ingredient of the cake is a large chocolate bar, lying unwrapped on the kitchen table. The bar is an M \times NM×N rectangular grid of chocolate blocks. All of the MNMN blocks are rectangles of identical shape and size. The chocolate bar is of top quality and the friends want to eat part of it, before the rest is used in the cake.

“OK,” says Quido, "let’s divide the whole bar into two triangular chunks by a straight diagonal cut from its upper-left corner to its lower-right corner. We will then eat all of the blocks which have been cut exactly in half, into two equal-area pieces. You will eat one half and I will eat the other half of each such block. All other blocks, that is, the blocks which are either uncut or cut into two parts of different sizes, will go directly into the cake. Of course, we will make sure the cut is perfectly precise.

Let’s see how much chocolate we get to eat!"

输入描述:
The input consists of two space-separated integers MM and NN given on a single line, (where 1 ≤ M, N ≤ 10^{18}1≤M,N≤10
18
). The numbers MM and NN denote the number of blocks in one column and in one row, respectively, in the chocolate bar.
输出描述:
Print the number of blocks of the chocolate bar which are cut into exactly two pieces of equal area.
示例1
输入
复制
6 10
输出
复制
2
示例2
输入
复制
75206452536745713 10322579177493903
输出
复制
40318322589

【题目分析】

对角线能够切的小方块数目,其实用Excel表格画一下会更直观,你会发现当这两个数有最大公约数的时候,这个答案就和最大公约数有关,如果这两个数在除以最大公约数之后,仍然是奇数的话,就说明是可以切成几个小方块的,这题应该考察的就是做题经验吧

【代码展示】

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>
typedef long long ll;
using namespace std;

map<int,map<int,int> >flag;

stack<bool> s;

ll gcd(ll a,ll b)
{
    if(a<b)
        swap(a,b);
    return b == 0?a:gcd(b,a%b);
}


int main()
{
    ll m,n;
    cin>>m>>n;
    ll gcd2 = gcd(m,n);
    if((m/gcd2)%2==1 && (n/gcd2)%2 == 1)
        cout<<gcd2<<endl;
    else
        cout<<0<<endl;

    return 0;
}


C Gerrymandering

【题目描述】

格式太乱,点连接看吧

戳这里看题目哦

【题意理解】

就是一个简单的大模拟,按照题目说的要求,进行运算就好,也没什么坑,我就是水了一下就过了

【代码展示】

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>
typedef long long ll;
using namespace std;
map<int,map<int,int> >flag;

int a[10008][2];
int waste[10008][2];

int main()
{
    int P,D;
    int t,x,y;
    ll v = 0;
    cin>>P>>D;
    for(int i=1;i<=P;i++)
    {
        cin>>t>>x>>y;
        a[t][0] += x;
        a[t][1] += y;
        v += (x+y);
    }

    int sum_b = 0,sum_a = 0;
    for(int i=1;i<=D;i++)
    {
        if(a[i][0]>a[i][1])
        {//A获胜
            waste[i][0] = a[i][0] - ((a[i][0]+a[i][1])/2+1);
            waste[i][1] = a[i][1];
            cout<<"A "<<waste[i][0]<<" "<<waste[i][1]<<endl;
        }
        else{
            waste[i][0]= a[i][0];
            waste[i][1] = a[i][1]  - ((a[i][0]+a[i][1])/2+1);
            cout<<"B "<<waste[i][0]<<" "<<waste[i][1]<<endl;
        }
         sum_a += waste[i][0];
         sum_b += waste[i][1];
    }

    int cha = abs(sum_a-sum_b);
    double ans = (double)cha*1.0/(double)v*1.0;
    printf("%.10lf\n",ans);
    return 0;
}



D Missing Numbers

戳这里看签到题目
开具之前我就敲好的代码,但是换了一台机子,就有重新敲了一遍,但是太过于自信了,连样例都没试,就交了,结果,成功伐时,拖队友后退

【代码展示】

# include<bits/stdc++.h>
using namespace std;
//不打算补得,但是辛辛苦苦写出来的,全当买个教训啦
int n;
int book[207];
int a[207];
int main()
{
	
	cin>>n;
	bool flag = true;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		book[a[i]]=1;
	}
	
	for(int i=1;i<=a[n];i++)
	{
		if(book[i]==0)
		{
			flag = false;
			cout<<i<<endl;
		}
	}
	
	if(flag)
	cout<<"good job"<<endl;
	
	return 0;
}

G Research Productivity Index

不要问我中间的两个怎么不写,我是真的不会

【题目描述】

链接:https://ac.nowcoder.com/acm/contest/13168/G
来源:牛客网
Angela is a new PhD student and she is nervous about the upcoming paper submission deadline of this year’s research conference. She has been working on multiple projects throughout the past year. Luckily most of the projects concluded successfully, and she came up with nn candidate papers. However not all of the papers were born equal——some have better results than others. Her advisor believes she should only submit the papers with “good enough” results so they have a high chance of getting accepted.

Angela’s research group has a unique way of evaluating the success of paper submissions. They use the research productivity index, defined as a^{a/s}a
a/s
, where ss is the total number of papers submitted, and aa is the number of papers that are accepted by the conference. When a = 0a=0, the index is defined to be zero. For example:

if one paper is submitted and it gets accepted, the index is 1^{1/1} = 11
1/1
=1;

if 4 papers are submitted and all get accepted, the index is 4^{4/4} = 44
4/4
=4;

if 10 papers are submitted and 3 get accepted, the index is 3^{3/10} ≈ 1.3903893
3/10
≈1.390389;

if 5 papers are submitted and 4 get accepted, the index is 4^{4/5} ≈ 3.0314334
4/5
≈3.031433;

if 3 papers are submitted and all get rejected (a = 0), the index is 0.

Intuitively, to get a high research productivity index one wants to get as many papers accepted as possible while keeping the acceptance rate high.

For each of her nn papers, Angela knows exactly how likely it is that the conference would accept the paper. If she chooses wisely which papers to submit, what is the maximum expected value of her research productivity index?

输入描述:
The first line of the input has a single integer n~ (1 \leq n \leq 100)n (1≤n≤100), the number of Angela’s candidate papers. The next line has nn space-separated integers giving the probability of each paper getting accepted. Each probability value is given as an integer percentage between 11 and 100100, inclusive.
输出描述:
Output the maximum expected value of Angela’s research productivity index. Your answer is considered correct if it has an absolute or relative error of no more than 10^{−6}10
−6
.
示例1
输入
复制
5
30 50 70 60 90
输出
复制
2.220889579
示例2
输入
复制
6
30 90 30 90 30 90
输出
复制
2.599738456
示例3
输入
复制
4
10 10 10 10
输出
复制
0.368937005

【代码展示】

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>
typedef long long ll;
using namespace std;
map<int,map<int,int> >flag;

int n;
int tot,now;
double a[105];
double dp[102][102];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        a[i] = x*0.01;
    }
    sort(a+1,a+1+n,greater<double>());
    dp[0][0] = 1;
    double ans = 0;

    for(int i=1;i<=n;i++)
    {
        dp[i][0] = dp[i-1][0]*(1-a[i]);
        for(int j=1;j<=i;j++)
        {
            dp[i][j] = dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
        }
        double now = 0;
        for(int j=1;j<=i;j++)
        {
            now += dp[i][j]*pow(j,1.0*j/i);
        }
        ans = max(ans,now);
    }
    printf("%.9f\n",ans);
    return 0;
}


H Running Routes

【题目描述】

链接:https://ac.nowcoder.com/acm/contest/13593/H
来源:牛客网
The administrators at Polygonal School want to increase enrollment, but they are unsure if their gym can support having more students. Unlike a normal, boring, rectangular gym, the gym floor at Polygonal is a regular nn-sided polygon! They affectionately refer to the polygon as PP .

The coach has drawn several running paths on the floor of the gym. Each running path is a straight line segment connecting two distinct vertices of PP . During gym class, the coach assigns each student a different running path, and the student then runs back and forth along their assigned path throughout the class period. The coach does not want students to collide, so each student’s path must not intersect any other student’s path. Two paths intersect if they share a common point (including an endpoint).

Given a description of the running paths in PP , compute the maximum number of students that can run in gym class simultaneously.

Figure H.1: Illustrations of the two sample inputs, with possible solutions highlighted in thick red lines. Solid black lines represent running paths that are not assigned to a student, and dashed black lines are used to show the boundary of PP in places where no running path exists.

【输入描述】

The first line contains an integer n (3 \leq n \leq 500)n(3≤n≤500), the number of vertices in PP . (The vertices are numbered in increasing order around PP .) Then follows nn lines of nn integers each, representing a n \times nn×n symmetric binary matrix which we’ll call MM . The jj-th integer on the ii-th line M_{ij}M ij is 11 if a running path exists between vertices ii and jj of the polygon, and 00 otherwise. It is guaranteed that for all 1 \leq i,j \leq n1≤i,j≤n, M_{ij} = M_{ji}M ij =M ji and M_{ii} = 0M ii​ =0.

【输出描述】

Print the maximum number of students that can be assigned to run simultaneously on the running paths, given the above constraints.
示例1
输入
复制
3
0 1 1
1 0 1
1 1 0
输出
复制
1
示例2
输入
复制
6
0 0 0 1 0 0
0 0 0 0 1 1
0 0 0 0 1 1
1 0 0 0 0 0
0 1 1 0 0 0
0 1 1 0 0 0
输出
复制
2

【题意解读】

  1. 这道题目就是给你一个图,以及那些边有连接,示例中的ij=1表明i与j之间有一条边。然后让你求出最多有几条不交叉的边,交叉在点上也不行,

【考点剖析】

  1. 这是一个区间dp问题,建议在做这个问题的时候,提前学习一下石子合并问题,这是一个很好的区间DP的入门题,只要掌握区间DP的原理,学会一步步的找到地推公式,就可以解决这道问题。
  2. 所以分析这道题目,就会发现,考虑将n边形按照编号排成一圈,一个区间为[l,r],假设在[l,r]中有一个点p向l连接一条线,那么区间[l+1,p-1] 里的点就不能再想[p+1,r]中的点连线了,由此可以设f(l,r)标书区间[l,r]中最多能连几条线,呢么状态转移方程就是f(l,r) = max(f(l+1)(p-1)+f(p+1,r)+a[l][p])

【代码展示】

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>


#define For(i,a,b)for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
map<int,map<int,int> >flag;


int n,len,a[600][600],f[600][600];

int main()
{
    scanf("%d",&n);
    For(i,1,n)For(j,1,n) scanf("%d",&a[i][j]);
    for(int len = 1;len<=n-1;len++)
    {
        for(int i=1;i<= n-len;i++)
        {
            for(int k = i;k<=i+len ;k++)
            {
                f[i][i+len] = max(f[i][i+len],f[i+1][k-1] + f[k+1][i+len] + a[i][k]);
            }
        }
    }

    printf("%d\n",f[1][n]);
    return 0;
}

I Slow Leak

链接:https://ac.nowcoder.com/acm/contest/13593/I
来源:牛客网

【题目描述 】

You are an avid cyclist and bike every day between your home and school. Usually, your ride is uneventful and you bike along the shortest path between home and school. After school this afternoon you realized you have a slow leak in your bike tire——the tire can hold some air, but not for long. Refilling the tire allows you to ride your bike for some distance, after which your tire goes flat again and it becomes impossible to ride any further (and you refuse to walk your bicycle).

Luckily for you, your city has installed several bike repair stations at intersections throughout town where you can refill your tire and bike again until the tire goes flat. There’s a repair station at your school too, so that you can fill up your tire before you start on your trip home.

You’ve calculated how far you can bike before your tire runs out of air and you know the layout of your town, including all the intersections, distances between them, and the locations of the repair stations. What is the shortest possible trip from school to your home that you can take without becoming stuck due to a flat tire? (You do not become stuck if you roll into a repair station, or your home, at the exact same time as your tire goes flat.)

【输入描述】

The first line of input contains four integers nn, mm, tt, and dd, satisfying 2 \leq n \leq 5002≤n≤500, 0 < m \leq n*(n - 1)/20<m≤n∗(n−1)/2, 0 < t < n0<t<n and 0 < d < 2^{31}0<d<2
31
. The value nn represents the number of intersections in the city, mm represents the number of roads in the city, tt is the number of repair stations and dd is the distance that you can bike (starting with a fully inflated tire) before your tire goes flat again. The intersections are numbered from 11 to nn. Your school is at intersection 11 and your home is at intersection nn.

The second line of input contains tt integers, with values between 22 and n − 1n−1, inclusive. These are the intersections where the repair stations are located (excluding your school’s repair station). All integers on this line are unique.

The next mm lines represent the roads in your town. Each has three integers i, j, ki,j,k, where 1 \leq i < j \leq n1≤i<j≤n, and 0 < k < 2^{31}0<k<2
31
. These three integers represent that there is a direct road from intersection ii to intersection jj of length kk. Roads can be traveled in either direction. There is at most one road between any two intersections.

【输出描述】

Print the minimum total distance you need to travel to reach home from school without getting stuck due to a flat tire. If the trip is not possible, output the word stuck on a single line instead.

It is guaranteed that if the trip is possible, the minimum distance DD satisfies 0 < D < 2^{31}0<D<2
31
.

示例1
输入
复制
6 7 2 4
2 5
1 2 4
1 3 5
2 3 3
3 4 2
3 5 1
4 6 4
5 6 4
输出
复制
12
示例2
输入
复制
6 7 2 10
2 5
1 2 1
1 3 2
2 3 1
3 4 8
4 5 3
4 6 2
5 6 1
输出
复制
stuck
备注:
In the first sample input, if your tire did not have a leak then the shortest path home would have a distance of 99, going from the school through intersections 33 and 55. However, due to the leak, you can only travel a distance of 44 before you need to refill the tire, requiring you to use the repair stations at intersections 22 and 55, for a total distance of 1212.

In the second sample input, if your tire did not have a leak, then the shortest path home would have a distance of 1212. But since your tire only lasts for a distance of 1010, there’s no path where your bike tire will not go flat somewhere along the way. Even when using repair station at intersection 22, you get stuck before you can reach either your home or the repair station at intersection 55.

【题意分析】

就是说给你了从学校到家的一张图,其中有n个结点,m条边,t个修理站,已经你的自行车能走的最大距离d,让你求在自行车可以行驶的条件下,到家的最短距离,若无法走通,就输出stuck;

【考点剖析】

考察的是Floyd算法的运用,先把所有节点的信息保存到图中,使用Floyd算法堆所有节点跑一遍最短路径,然后单独抽出最短路径中节点距离大于d的,这条路作废,然后在把学校作为第一个修理站,家作为最后一个修理站,把所有的修理站在刚刚计算的最短路中跑一遍,如果跑完后发现f[1][n] == inf,就说明无路可走

【代码展示】


#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>


#define For(i,a,b)for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
map<int,map<int,int> >flag;

const ll inf  = 1e18;
const int N = 510;

int n,m,t;
ll d;
ll f[N][N];
int p[N];

int main()
{
    scanf("%d%d%d",&n,&m,&t);
	scanf("%lld",&d);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i==j) f[i][j] = 0;
            else
                f[i][j] = inf;
        }
    }

    for(int i=1;i<=t;i++)
    {
        scanf("%d",&p[i]);
    }

    for(int i=0;i<m;i++)
    {
        int a,b;
        ll c;
        scanf("%d%d",&a,&b);
        scanf("%lld",&c);
        f[a][b] = f[b][a] = c;
    }

    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                f[i][j] = min(f[i][j],f[i][k]+f[k][j]);
        }
    }

    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        if(f[i][j]>d)
            f[i][j] =  inf;
    }

    p[0] = 1;
    p[t+1] = n;

    for(int k=0;k<=t+1;k++)
        for(int i=0;i<=t+1;i++)
            for(int j=0;j<=t+1;j++)
            f[p[i]][p[j]] = min(f[p[i]][p[j]],f[p[i]][p[k]] + f[p[k]][p[j]]);

        if(f[1][n] == inf)
            puts("stuck");
        else
            printf("%lld\n",f[1][n]);
    return 0;
}


J Stop Counting!

【题目描述】

链接:https://ac.nowcoder.com/acm/contest/13593/J
来源:牛客网

The Martingale casino is creating new games to lure in new gamblers who tire of the standard fare. Their latest invention is a fast-paced game of chance called Stop Counting!, where a single customer plays with a dealer who has a deck of cards. Each card has some integer value.

One by one, the dealer reveals the cards in the deck in order, and keeps track of the sum of the played cards and the number of cards shown. At some point before a card is dealt, the player can call “Stop Counting!” After this, the dealer continues displaying cards in order, but does not include them in the running sums. At some point after calling “Stop Counting!”, and just before another card is dealt, the player can also call “Start Counting!” and the dealer then includes subsequent cards in the totals. The player can only call “Stop Counting!” and “Start Counting!” at most once each, and they must call “Stop Counting!” before they can call “Start Counting!”. A card is “counted” if it is dealt before the player calls “Stop Counting!” or is dealt after the player calls “Start Counting!”

The payout of the game is then the average value of the counted cards. That is, it is the sum of the counted cards divided by the number of counted cards. If there are no counted cards, the payout is 0.

You have an ‘in’ with the dealer, and you know the full deck in order ahead of time. What is the maximum payout you can achieve?

【输入描述】

The first line of the input contains a single integer 1 \leq N \leq 1000 0001≤N≤1000000, the number of cards in the deck.

The second line of input contains NN space-separated integers, the values on the cards. The value of each card is in the range [−10{9},10{9}][−10
9
,10
9
]. The cards are dealt in the same order they are given in the input.

【输出描述】

Output the largest attainable payout. The answer is considered correct if the absolute error is less than 10^{−6}10
−6
, or the relative error is less than 10^{−9}10
−9
.
示例1
输入
复制
5
10 10 -10 -4 10
输出
复制
10.000000000
示例2
输入
复制
4
-3 -1 -4 -1
输出
复制
0.000000000
备注:
In the first sample, by calling “Stop Counting!” before the -10−10 and “Start Counting!” before the final 1010, we can achieve an average of 10.010.0 with the cards that are counted.

In the second sample, all values are negative, so the best strategy is to call “Stop Counting!” before the first card is dealt and call “Start Counting!” after the last card is dealt. Since no cards were counted, the average of the counted cards is 0.00.0.

【题意分析】

给你一段序列,让你从中截取一段,求剩余的那一部分的平均值最大是多少;
因为最大的平均值一定是在两端取得,不管是左或右,只有一个是最大值,所以从前到后扫描一遍,在从后向前扫描一遍,利用前缀和,以及后缀和的原理,求出,前一部分和后一部分的最大平均值,去一个最大的就好了

【代码如下】


#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>


#define For(i,a,b)for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
map<int,map<int,int> >flag;

int a[1000199];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }

    double ans1 = 0,ans2 = 0,sum1 = 0,sum2 = 0;
    for(int i=1;i<=n;i++)
    {
        sum1 += a[i];
        ans1 = max(ans1,sum1/i);
    }
    for(int i=n;i>=1;i--)
    {
        sum2 += a[i];
        ans2 = max(ans2,sum2/(n-i+1));
    }

    printf("%.9f\n",max(ans1,ans2));

    return 0;
}

K Summer Trip

【题目描述】

链接:https://ac.nowcoder.com/acm/contest/13593/K
来源:牛客网

Leo has started a job in a travel agency. His first task is to organize a summer trip to an exotic overseas city. During the summer season, events of various types take place in the city: sports matches, concerts, beach parties, and many others. At any given time, there is exactly one event taking place. Events of any particular type may take place more than once during the season. The itinerary of events that Leo offers to his clients cannot be chosen arbitrarily; the company requires them to form a so-called “good itinerary.” A good itinerary is a consecutive sequence of at least two events in the summer season, where the first and last events are of different types, and they are both unique among all event types during the sequence. For example, if the first event in a good itinerary is a beach party, none of the other events during the itinerary can also be a beach party. There are no other restrictions on the event types in the sequence of a good itinerary.

Before he starts organizing the trip, Leo wants to know the total number of good itineraries that are possible given a calendar of events that will take place over the summer season.

【输入描述】

The input consists of one line with a string describing the sequence of event types in the summer season. All characters are lowercase English letters (a - z)(a−z), with different letters represent different types of events. Character ii of the string encodes the ii-th event of the summer. There are no blanks or spaces in the string.

The length of the input string is at least 22 and at most 100 000100000 characters.

【输出描述】

Print the number of good itineraries that exist for the given summer season.
示例1
输入
复制
abbcccddddeeeee
输出
复制
10
示例2
输入
复制
thenumberofgoodstringsis
输出
复制
143

【题意分析】

题目的意思就是给你一个字符串让你找一种子串的数量,这种子串要满足,首尾的字母不能相同,中间的字母也不能和首尾的字符相同,所以要设置首尾两个指针i,j这就代表着子串的开头和结尾的位置,然后分别枚举他们中间的所有字符,只要符合条件,就计数。

【代码展示】

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<map>


#define For(i,a,b)for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
map<int,map<int,int> >flag;

int main()
{
    ll sum = 0;
    string str;
    cin>>str;
    int len = str.length();
    for(int i=0;i<len-1;i++)
    {
        if(str[i]!=str[i+1])
        {


             for(int j=i+1;j<len;j++)
            {
                if(str[j]==str[i])
                    break;
                int f = 0;
                if(str[j]!=str[j-1])
                {
                     for(int k = i+1;k<j;k++)
                    {
                        if(str[j]==str[k])
                        {
                            f = 1;
                            break;
                        }
                    }
                    if(f == 0)
                    {
                        sum ++;
                    }
                }

            }
            }
    }
    cout<<sum<<endl;
    return 0;
}

M Zipline

【题目描述】

链接:https://ac.nowcoder.com/acm/contest/13593/M
来源:牛客网

A zipline is a very fun and fast method of travel. It uses a very strong steel cable, connected to two poles. A rider (which could be a person or some cargo) attaches to a pulley which travels on the cable. Starting from a high point on the cable, gravity pulls the rider along the cable.

Your friend has started a company which designs and installs ziplines, both for fun and for utility. However, there’s one key problem: determining how long the cable should be between the two connection points. The cable must be long enough to reach between the two poles, but short enough that the rider is guaranteed to stay a safe distance above the ground. Help your friend determine these bounds on the length.

The cable connects to two vertical poles that are ww meters apart, at heights gg and hh meters, respectively. You may assume that the cable is inelastic and has negligible weight compared to the rider, so that there is no sag or slack in the cable. That is, at all times the cable forms two straight line segments connecting the rider to the two poles, with the sum of the segments lengths equal to the total length of the cable. The lowest part of the rider hangs rr meters below the cable; therefore the cable must stay at least rr meters above the ground at all times during the ride. The ground is flat between the two poles. Please refer to the diagram in Figure M.1 for more information.

在这里插入图片描述

Figure M.1: A zipline, annotated with the four variables used to describe it.

【输入描述】

The input starts with a line containing an integer nn, where 1 \leq n \leq 1 0001≤n≤1000. The next nn lines each describe a zipline configuration with four integers: ww, gg, hh, and rr. These correspond to the variables described above. The limits on their values are: 1 \leq w, g, h \leq 1 000 0001≤w,g,h≤1000000, and 1 \leq r \leq min(g, h)1≤r≤min(g,h).

【输出描述】

For each zipline, print a line of output with two lengths (in meters): the minimum and maximum length the cable can be while obeying the above constraints. Both lengths should have an absolute error of at most 10^{−6}10
−6
.
示例1
输入
复制
2
1000 100 100 20
100 20 30 2
输出
复制
1000.00000000 1012.71911209
100.49875621 110.07270325

【题意分析】

这就是一道纯正的数学题,给你两个柱子的高度,在两个主子的上方拉绳子,绳子最长的时候距离地面的距离为r,当然最短的距离一定是两个柱子顶端的直线距离。

【代码展示】

#include <bits/stdc++.h>
#define ll long long
using namespace std;
char a[100],b[10000];
stack<int> s;
int main()
{
    double w,g,h,r;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf",&w,&g,&h,&r);
        
        if(h+g==2*r)//如果说r在g和h的连线上,说明最长和最短距离是一样的
        {
            double ans4=sqrt((h-g)*(h-g)+w*w);
            printf("%.8lf %.8lf\n",ans4,ans4);
        }
        
        else
        {
            double ans1=sqrt((g-r)*(g-r)+w*w*((g-r)/(h+g-2*r))*((g-r)/(h+g-2*r)));
            double ans2=sqrt((h-r)*(h-r)+w*w*((h-r)/(h+g-2*r))*((h-r)/(h+g-2*r)));
            double ans3=sqrt((h-g)*(h-g)+w*w);
            printf("%.8lf %.8lf\n",ans3,ans1+ans2);
        }
    }
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值