Team Game Seven

Write down questions that you find meaningful

Big fish eat small fish 51Nod - 1289 

There are N fish, each with different positions and sizes, and they swim along the X-axis, some to the left, some to the right. The swimming speed is the same, two fish meet the big fish will eat the small fish. The size and swimming direction of each fish are given from left to right (0 means left, 1 means right). After enough time, how many fish can be left? Input line 1: 1 number N, indicating the number of fish (1 <= N <= 100000). 
Lines 2 - N + 1: two numbers A i per linei , B ii , separated by spaces, respectively indicate the size of the fish and the direction of swimming (1 <= A ii <= 10^9,B ii  = 0 or 1, 0 means left, 1 means right). Output outputs 1 number, indicating the number of fish left in the end. Sample Input
5
4 0
3 1
2 0
1 0
5 0
Sample Output
2

I know this is a water problem, but I didn't think about using the stack one hour before the game, so I thought about it for a long time. My teammates said that I had set a question. I found that I could pass it directly with the stack. I will remind myself to think about it in the future!

#include<stdio.h>
#include<string.h>
#include<queue>
#include<set>
#include<stack>
using namespace std;
intmain()
{
    stack<int>q;
    int n,a,b,sum;
    scanf("%d",&n);
    sum = n
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        if(b==1)
            q.push(a);
        else
        {
            while(!q.empty())
            {
                int s=q.top();
                if(a>s)
                {
                    sum--;
                    q.pop();
                }
                else
                {
                    sum--;
                    break;
                }
            }
        }
    }
    printf("%d\n",sum);
}
Smart Carpenter    51Nod - 1117 

An old carpenter needs to cut a long wooden stick into N pieces. The length of each segment is L1, L2, ..., LN (1 <= L1, L2, ..., LN <= 1000, and all are integers) length units. We consider cutting only at integer points without loss of wood.
The carpenter found that the physical strength spent on each cut is proportional to the length of the stick, so it may take 1 unit of physical strength to cut a stick with a length of 1. For example: if N=3, L1 = 3, L2 = 4, L3 = 5, the original length of the stick is 12, and the carpenter can cut it in various ways, such as: first cut 12 into 3+9. It costs 12 stamina , then cut 9 into 4+5, spend 9 stamina, and spend a total of 21 stamina; you can also cut 12 into 4+8, spend 12 stamina, then cut 8 into 3+5, spend 8 stamina, and spend a total of 20 physical strength. Obviously, the latter is more energy efficient than the former.
So, how much physical effort does a carpenter have to spend at least to complete the cutting task?
Input Line 1: 1 integer N (2 <= N <= 50000) 
Line 2 - N + 1: 1 integer Li per line (1 <= Li <= 1000). Output outputs minimal physical exertion. Sample Input
3
3
4
5
Sample Output
19

Simple and greedy, someone did it with a set, I think it would be better to use a priority queue, reverse thinking, and find the smallest sum of the two each time.

#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
priority_queue<int ,vector<int >,greater<int> >q;
intmain()
{
    int n,x;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
      scanf("%d",&x);
      q.push(x);
    }
    int ans=0;
    int a,b;
    while(q.size()>1)
    {
        a=q.top();
        q.pop();
        b=q.top();
        q.pop();
        ans+=a+b;
        q.push(a+b);
    }
    printf("%d\n",ans);
    return 0;
}

Friend Number II   zoj3336

Given a positive integer x, let S(x) denotes the sum of all x's digits. Two integers x and y are friend numbers if S(x)=S(y). Here comes the problem: Given a positive integer x, of course it has a lot of friend numbers, find the smallest one which is greater than x,please.

Input

There are multiple test cases. The first line of input is an integer T (0<T<230) indicating the number of test cases. Then T test cases follow. Each case is an integer x (0<x<=101000).

Output

For each test case, output the result integer in a single line.

Sample Input

3
12
19
222

Sample Output

21
28
231

Note: No input data start with digit 0 and you should not output a number starts with 0.

The meaning of the question: find the sum of each number for which y is equal to x, and y must be greater than x, and the smallest one

Idea: I thought it was all plus 9, but a set of samples 9991 failed. Then I found that I first found the number that is not 0 at the end, subtracted it by 1, and then continued to find the number that was not 9 and added 1, because 9 involves gold It is a matter of taste, so I don't consider him. If you can't find a number other than 9 after searching, then fill in a 1 manually. If there is a group example such as 5299, then we will find it and it will become 5398, then let 98 sort it.

#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
char s[100005];
intmain()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",s);
        int len=strlen(s),j;
        for(int i=len-1;i>=0;i--)
        {
            if(s[i]!='0')
            {
                s[i]--;
                j=i-1;
                break;
            }
        }
        for(j;j>=0;j--)
        {
            if(s[j]!='9')
            {
                s[j]++;
                break;
            }
        }
        if(j<0)
            printf("1");
        sort(s+j+1,s+len);
        printf("%s\n",s);
    }
}

Warship Game  51Nod - 1521 

At the beginning of the game, Alice puts k battleships in this table without telling Bob the exact location. The shape of each battleship is a 1×a rectangle (that is, the battleship will occupy a contiguous square). These battleships cannot overlap each other nor touch each other.

Then Bob would do a series of roll calls. When he clicks on a certain square, Alice will tell him whether that square is occupied by a certain battleship. If yes, say hit, otherwise say miss.

But here is a problem! Alice likes to lie. He would tell Bob miss every time.

Please help Bob to prove that Alice lied, please find out which step Alice must lie after.


Input single set of test data. 
The first line has three integers n, k and a (1≤n,k,a≤2*10^5), indicating the size of the table, the number of battleships, and the size of the battleship. The input n,k,a is guaranteed to be able to put k battleships of size a in the 1×n table, and they do not overlap or touch. 
The second line is an integer m (1≤m≤n), which represents the number of roll calls made by Bob. 
The third line has m different integers x1,x2,...,xm, and xi is the grid number of Bob's ith roll call. The cells are numbered from 1 to n from left to right. Output outputs an integer representing the earliest roll call number that can prove Alice must lie. If it cannot be proven, output -1. The roll call numbers are numbered from 1 to m in order. Sample Input
Example 1
11 3 3
5
4 8 6 1 11

Example 2
5 1 3
2
1 5
Sample Output
Sample output 1
3

Sample output 2
-1

Idea: At the beginning, first find all the most and put a few, then find a point to remove each time, and then see how many can be put, each time subtract the number that can no longer be put, if the number of warships is small It is enough to output the number of m for k. In addition, pay attention to one point. The battleship cannot touch, so it must be divided by a+1 every time.

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
#define ll long long
int v[2*100005];
intmain()
{
    memset(v,0,sizeof(v));
    int n,k,a;
    scanf("%d%d%d",&n,&k,&a);
    int m;
    scanf("%d",&m);
    int maxx=(n+1)/(a+1),x,l,r,ans,flag=-1;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&x);
        v[x]=1;
        for(l=x-1;l>=1&&v[l]==0;l--);
        for(r=x+1;r<=n&&v[r]==0;r++);
        ans=(rl)/(a+1)-(xl)/(a+1)-(rx)/(a+1);
        maxx-=ans;
        if(maxx<k&&flag==-1)
        {
            flag=i;
            break;
        }
    }
    printf("%d\n",flag);
}

Supplement: FZU-2148

Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N starts in the sky which we can just consider each as a point. After he draws these stars, he starts to sing the famous song “The Moon Represents My Heart” to Maze.

You ask me how deeply I love you,

How much I love you?

My heart is true,

My love is true,

The moon represents my heart.

But as Fat brother is a little bit stay-adorable(呆萌), he just consider that the moon is a special kind of convex quadrilateral and starts to count the number of different convex quadrilateral in the sky. As this number is quiet large, he asks for your help.

Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains an integer N describe the number of the points.

Then N lines follow, Each line contains two integers describe the coordinate of the point, you can assume that no two points lie in a same coordinate and no three points lie in a same line. The coordinate of the point is in the range[-10086,10086].

1 <= T <=100, 1 <= N <= 30

Output

For each case, output the case number first, and then output the number of different convex quadrilateral in the sky. Two convex quadrilaterals are considered different if they lie in the different position in the sky.

Sample Input
2
4
0 0
100 0
0 100
100 100
4
0 0
100 0
0 100
10 10
Sample Output
Case 1: 1
Case 2: 0

Alas, I ran out of time during the competition. Later, I looked at the problem and found that it was quite simple. Consider the concave package.

The meaning of the question: give you n points, see how many convex hulls can be formed, we will do the opposite and find the concave hull, because it is a quadrilateral, the concave hull is that the fourth point must be in the triangle formed by the other three points , then the area of ​​the triangle formed by the other three points is the sum of the triangle formed by the other three points and the fourth point. Sabc=Sabd+Sbcd+Sacd. Then we only need to judge that it is not a concave bag.

#include<math.h>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
const double esp=10e-6;
struct point
{
    int x;
    int y;
};
double area(point a, point b, point c)
{
    return fabs(1.0*((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)))/2.0;
}
bool check(point a, point b, point c, point d)
{
    if (fabs(area(a,b,c)-area(a,b,d)-area(b,c,d)-area(a,c,d))<esp)
        return 0;
    return 1;
}
int main()
{
    int t,casee=0;
    scanf("%d",&t);
    while(t--)
    {
        point p[35];
        int n;
        int cnt = 0;
        scanf("%d",&n);
        for (int i = 0; i < n; i++)
            scanf("%d%d",&p[i].x,&p[i].y);
        for (int i=0; i<n; i++)
            for (int j=i+1; j<n; j++)
                for (int k=j+1; k<n; k++)
                    for (int l=k+1; l<n; l++)
                    {
                        if (check(p[i],p[j],p[k],p[l])&&check(p[i],p[l],p[k],p[j])&&check(p[i],p[j],p[l],p[k])&&check(p[l],p[j],p[k],p[i]))
                            cnt++;
                    }
        printf("Case %d: %d\n",++casee,cnt);
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325943147&siteId=291194637