Simulation game school (b) (9.12)

Problem 1: the non-negative part and 
[title] Description 
  WZK recently received a task. 
N is given a sequence number, as A0, A1 An ,,,, - . 1 , after the cyclic shift k bits, which 
became Ak, Ak + . 1 ,,,, An- . 1 , A0, A1 ,,,, AK- 1 . An excellent cycle movement, the 
front I ( . 1 <= I <= n-) are satisfied and the term is not less than zero. Please give this excellent cyclic shift sequence number. 
  This question is of course very simple matter, but WZK busy eating small raccoon face altogether, do not write oily hands 
are trouble you! If you can do out, he will be considered a package you eat oh ~  
 
[Input format 
  of the first line of an integer n-( . 1 <= n-<= 10 ^ . 6 ), expressed the number n. 
  The second line n integers, Ai ( - 1000 <= Ai <= 1000 ) represents the i-th analysis. 
 
[] Output format 
  line an integer representing the number of outstanding rotated.
 
[Sample input] 
. 3  
2  2  . 1  
 
[] Sample Output
View Code

Amazing questions, direct monotonous queue maintains enough

It is easy to push out the formula, qwq

#include<bits/stdc++.h>
#define I inline
using namespace std;
const int N=1e6+7;
int a[N],s[N*2],n,ans;
deque<int> que;
I int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
    freopen("sum.in","r",stdin);
    freopen("sum.out","w",stdout);
    n=read();
    for (int i=1;i<=n;i++)
    s[i]=s[i-1]+read(),s[i+n]=s[i];
    for (int i=n+1;i<=2*n;i++) s[i]+=s[n];
    que.push_back(1);
    for (int i=1;i<n;i++)
    {
        while (!que.empty()&&s[que.back()]>s[i]) que.pop_back();
        que.push_back(i);
    }
    for (int i=n;i<2*n;i++)
    {
        if (que.front()<=i-n) que.pop_front();
        while (!que.empty()&&s[que.back()]>s[i]) que.pop_back();
        que.push_back(i);
        if (s[que.front()]-s[i-n]>=0) ans++;
    }
    printf("%d\n",ans);
    return 0;
}
View Code

The second questions I still did not want to come out positive solutions

So I Gugu Gu, and I have a big brother would like beating and hanging, please teach me readily cut chant

Face questions as follows:

Description [title] 
  WZK crowd below contempt, and finally determined to lose weight. He found that very good tennis player's body, then 
got YJC friend to a tennis match. 
 
  The following is a simple talk about the scoring rules of the game of tennis: 
Bureau: a game only one player serve, the first to win at least 4 points and 2 points more than the rival player to win at least a 
bureau. Tennis per game scoring method is very special, from 0 Zhi 3 points are "zero" (love), "fifteen" (Fifteen), 
"thirty" (thirty) and "Forty" (forty). When the score, the score serving hand front. Therefore, " 30 to 0" is intended to 
thinking that serve to win the hand 2 points, while catcher yet to score. When both players have been 3 time-sharing, commonly called the "draw" 
(Deuce) instead of "40 to 40 ." After a tie a player another score, known as "preemption" (advantage), 
rather than scoring. If you lose a point in the case of pre-emption, he returned to a draw; such as Head Start and then get a point, to win a game. 
Disk: When a player has won at least four innings and two innings lead of at least more than the opponent, to win this disc. When the two sides win 
was number six innings - 6, then enter the "tie-break." 
Tie-break: tie-break, the score column indicates the number using the normal, first to get ahead by at least 7 points and 2 points player 
win.
Contest: win two of the players that is win the race. 
 
Although they are a very good relationship, WZK still want to win the game. WZK own painstaking research the probability of winning of 1 minute, WZK 
want to know he won a bureau, a probability disk and the entire game is. (If it is too low, let's better than a) 
 
[Input format 
  multiple sets of test data. 
  Each set of test data input line of a real number P ( 0 <= P <= 1 ), 1 represents WZK win probability score. 
 [Format] output 
  for each set of data, the output line 3 Ge 11 decimal places, respectively WZK won 1 , Office 1 plate and the whole match 
probability. 
 
Sample input [] 
0.5  
0.3  
0.7  
 
[] sample output 
0.50000000000  0.50000000000  0.50000000000  
0.09921103448  0.00016770463  0.00000008437  
0.90078896552  0.99983229537  0.99999991563 
View Code

The third question, my initial thought is that this arrangement can not get out after ah, there are 50! The number of permutations

As a result, after I found it amazing that we actually have a best strategy:

We set the current direction is the direction of 180 degrees, directly to the forward run, and then after all the remaining rotation angle, selecting a most recent angular distance of 360 degrees

Then run backward, turn left after the first operation done enough Yeah qwq, finally ans that is the law of cosines can be calculated

Question 3: WZK luxury cruise 
[title Description 
WZK after a lifetime of struggle, finally had enough money to buy a luxury cruise ship (in fact, is of little wooden boat), this boat 
can perform four kinds of instruction: 
    right X: where X is a integer from 1 to 719, the command causes the ship clockwise X degrees. 
    left X: wherein X is an integer from 1 to 719, this command is rotated counterclockwise so that the boat X degrees. 
    forward X: wherein X is an integer (1 to 1000 ), so that the distance X ship advances straight ahead. 
    backward X: wherein X is an integer (1 to 1000 ), so that the distance X proceeds to the ship immediately behind. 
WZK n random write commands, he wanted to find a way to arrange one kind of command, making the boat reached the final position 
from the starting point as far. 
[Input format 
of the first line of an integer n-( . 1 <= n-<= 50 ), given the number of commands WZK. 
Next n lines, each line represents a command. 
 
Output Format] [ 
a float, it is possible to go the furthest distance, rounded to six decimal places. 
 
[Sample input] 
. 3  
Forward 100  
Backward 100  
left90  
 
[Sample output] 
141.421356 
View Code

The above is the title face, ugly code I offer the following:

#include<bits/stdc++.h>
#define db double
using namespace std;
const int N=101;
const double PI=acos(-1.0);
bool dp[51][N<<4];
int fro,bac,lf,rg;
struct node
{
    int d,opt;
} t[N];
int cnt,n;
double sqr(double x)
{
    return x*x;
}
int main()
{
    freopen("ship.in","r",stdin);
    freopen("ship.out","w",stdout);
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
    char s[N];scanf("%s",s);
    int x;scanf("%d",&x);
    if (s[0]=='f') fro+=x;    
    if (s[0]=='b') bac+=x;
    if (s[0]=='l') t[++cnt].d=x,t[cnt].opt=0;
    if (s[0]=='r') t[++cnt].d=x,t[cnt].opt=1;
    }
    dp[0][180]=true;
    for (int i=1;i<=cnt;i++)
    {
        for (int j=0;j<360;j++)
        {
        if (dp[i-1][j])
        {    
            dp[i][j]=dp[i-1][j];
            if (t[i].opt) dp[i][(j-t[i].d+720)%360]=true;
            else dp[i][(j+t[i].d)%360]=true;
            }    
        }
    }
    int a=0,b=0,p;
    for (int i=0;i<=180;i++) if (dp[cnt][i]) {a=i;break;}
    for (int i=359;i>=180;i--) if (dp[cnt][i]) {b=i;break;}
    p=min(a,360-b);p=180-p;
    double fp=cos(p/180.0*PI);
    double ans=sqrt(sqr((db)fro)+sqr((db)bac)-2*fro*bac*fp);
    printf("%.6lf\n",ans);
    return 0;
}
View Code

Middle to do a 01 bool type backpack, I believe we will do the right qwq

Guess you like

Origin www.cnblogs.com/Hale522520/p/11541214.html