{2018.5.7}Small summary of Xun (gou) and Yu (huo)'s second exam

Unconsciously on the second test;

Xun Yu did not finish the exam due to some things;

But I came back today and completed all the questions well;

indeed learned a lot;

1> Horror Costumes

Above topic:

【Problem Description】

Halloween is here again! The farmer, Cha, intends to take his cows to a fancy dress party, but Cha has only made a scary costume that can accommodate two cows whose total length does not exceed S (1 <= S <= 1,000,000) . Xiaocha raised N (2 <= N <= 20,000) cows numbered in the order of 1..N , and the length of the cow numbered i is Li (1 <= Li <= 1,000,000) . If the total length of the two cows does not exceed S , they can wear the suit.

Cha wondered how many satisfactions would there be if he wanted to choose two different cows to wear this suit

conditional scheme.

 

【enter】

* Line 1 : 2 integers separated by spaces: N and S * Line 2..N+1 : 1st integer i+1: Li

   

 

【Output】

* Line 1 : Output 1 integer, indicating the number of all options that Xiao Huang can choose. Note that the two programs with different order of cows
     are considered the same

 

【Input and output example 1

halloweena.in

halloween.out

4 6

3

5

2

1

 

4

 

[ Output description: ] The   4 options are: Cow 1 and Cow 3; Cow 1 and Cow 4; Cow 2 and Cow 4; Cow 3 and Cow 4.


  

【time limit】  

1s

 This is a very suitable subject for violent enumeration;

And the person who changed the title must be a lovely konjac from our talented class;

Thanks to Mr. Liu for not putting up disgusting test data;

Let the violent enumeration explode;

Instead ac;

Code for brute force enumeration:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,s,a[20100],ans=0;
cin>>n>>s;
for(int i=1;i<=n;i++)
    cin>>a[i];
for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    {if(a[i]+a[j]<=s)    ans++;    }cout<<ans<<endl;return 0;
   
   



}

Double-loop brute force search;

Let two cows be paired one by one;

simple and fast;

but!

I heard that this question can also be done with the dichotomy of making up a world;

No code is provided here;

After all, the dichotomy is not within my comprehension;

end...

2>Password lock

Above topic:

【Problem Description】

Once upon a time there was a sad story: Farmer Xiaozhang 's cows kept running away from his farm and caused huge losses.
To stop them escaping, he finds a magic lock to stop his cows from opening the fence gate.
This lock has three codons, each an integer from 1-n (1<=n<=100), 1 and n are adjacent because these codons are a circle. There are two sets codes to open the lock, one for the farmer Xiaozhang and the other for the locksmith. However, this lock has a small chance of being fault-tolerant and it will open as long as the number position on the dial does not differ by more than 2 from the corresponding number position on either combination . For example, if Xiaozhang 's password is (1,2,3 ), the locksmith's password is (4,5,6) . If your input is (1 , n, 5) (because this is very similar to Xiaozhang 's password) or (2,4 , 8) (because this is very similar to the locksmith's password) , the lock will open, . Note that (1,5,6 ) cannot open this lock because it is not close to any of the codes.
Given the chapter 's code and the locksmith's code, find the number of all different codes that can open the lock. Also, (1,2,3 ) and (3,2,1) are different.

 

【enter】

The first line: an integer n
The second line: 3 integers separated by spaces, representing the password of the chapter 3rd line: 3 integers separated by spaces, representing the password of the locksmith (probably the same as the password of the chapter )

 

【Output】

Number of passwords

 

 

【Input and output example 1

lock.in

lock.out

50

1 2 3

5 6 7

249

 

【time limit】  

1s

This question is still a question that someone just changed;

When I see this topic, I still think of violent enumeration;

opens a triple cycle of evil;

may time out;

but!

It was not thought through at the beginning;

Forgot that the absolute value of two numbers should be greater than n-3;

So... it's cool;

After thinking about it carefully;

The code is this:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a1,a2,a3,b1,b2,b3,ans=0;
cin>>n;
cin>>a1>>a2>>a3;
cin>>b1>>b2>>b3;
for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
        for(int k=1;k<=n;k++)
        {bool flag=0;if((abs(i-a1)>n-3||abs(i-a1)<3)&&(abs(j-a2)>n-3||abs(j-a2)<3)&&(abs(k-a3)>n-3||abs(k-a3)<3)&&flag!=1)    ans++,flag=1;                if((abs(i-b1)>n-3||abs(i-b1)<3)&&(abs(j-b2)>n-3||abs(j-b2)<3)&&(abs(k-b3)>n-3||abs(k-b3)<3)&&flag!=1)    ans++,flag=1;        }cout<<ans<<endl;return 0;
       
       






}

Triple loop + bool judgment;

A world can be violently created;

so;

Keep your mind clear when doing questions;

Check the conditions of the subject;

Don't start typing the code at a glance like Xun Yu did;

It often takes a lot of time and it is easy to make mistakes;

end...

3> Mushroom-picking tractor

Very good, it is still a topic that has been changed by someone;

The most difficult of the four questions in the test;

despair

Above topic:

【Problem Description】

    When spring comes, there will be a lot of mushrooms growing on Xiaofan's farm, and observing the cows driving the tractor to pick mushrooms has become Xiaofan's favorite thing to do.

    Xiaofan's farm is divided into a plane coordinate system, the coordinates of the lower left corner are (1, 1), and the coordinates of the upper right corner are (10^5, 10^5).

    Xiaofan has a radar to detect mushrooms. When the mushroom radar is turned on, the radar will find a mushroom on the farm every second, and will inform the coordinates of the mushroom.

    Xiaofan's cows will only drive the tractor in one direction, and will not turn. The direction here refers to the four directions parallel to the coordinate axis and the diagonal line with an angle of 45 degrees from the coordinate axis (of course, two opposite directions). corner). And Xiaofan only allows the cow to drive the tractor once a day, that is to say, every time he picks mushrooms, the tractor can only go in one direction to collect the mushrooms at the point it passes by.

    Xiaofan allows his cows to set off from any point on the farm, in any direction, and his tractor is so fast that the time it takes to complete the task is negligible. Now Xiao Fan wants to know what the earliest time to complete the task if he wants to collect K mushrooms at one time.

【enter】

In order to prevent fraud, the test data is divided into two groups, and the data format of each group is as follows:

The first line contains two integers N and K. Indicates that N mushrooms appear, and Xiaofan wants to collect K mushrooms.

       Next N lines, the ith line is two integers Xi and Yi, indicating that the coordinates of the mushroom found in the ith second are Xi and Yi.

       There is also the possibility of discovering multiple mushrooms one after another at a certain coordinate.

【Output】

There are two lines, each with an integer T, indicating that the collection of K mushrooms can be completed at the earliest T second. If the requirement cannot be met, then this line outputs -1.

 

[Input and output example 1]

tractor.in

tractor.out

4 3

1 2

3 4

3 2

4 5

5 2

1 1

2 1

1 2

1 3

 

4

2

From the fourth second, the 1st, 2nd, and 4th mushrooms can be collected.

 

【data range】

   50% data guarantee Xi, Yi is between [1..300]

  100% data guarantee that N is between [2..10^6] and K is between [2..N]. Xi and Yi are between [1..10^5].

Attach the comment code of the six-day boss of Zipan;

I have the same idea;

It's just that people have comments;

Let's see it more clearly:

#include<bits/stdc++.h>
using namespace std;
int a[100001],b[100001],c[200000],d[200000]; //First define four arrays, representing horizontal, vertical and diagonal Four directions of the line 
int n1,n2,k1,k2,xx,yy; //Because there are two sets of data, so I set it twice (to tell the truth, I was killed by this thing) 
int main()
{
cin> >n1>>k1;   
int flag1=0; //indicates that mushrooms cannot be picked yet 
for(int i=1;i<=n1;i++)
{
cin>>xx>>yy; //input mushroom coordinates 
a[xx] ++; //horizontal ++ 
b[yy]++; //vertical ++ 
c[100000+xx-yy]++; //upper left to lower right ++ 
d[200000-xx-yy ]++; //++ from the upper right to the lower left direction 
if(flag1==1) continue; //Indicates that it has been picked, this is to prevent repeated output, but because there are still mushroom coordinates that have not been read in, the loop is still Can't stop 
if(a[xx]>=k1||b[yy]>=k1) //Mushrooms are picked when the requirements are met (I am here to divide them into two because they are added later) 
    {cout<<i<<endl; flag1=1;}
if(c[100000+xx-yy]> =k1||d[200000-xx-yy]>=k1) 
    {cout<<i<<endl; flag1=1;}
}
if(!flag1) cout<<-1<<endl;    //表示没有达到要求 memset(a,0,sizeof(a));    //因为还有一组,所以要把数组清空     memset(b,0,sizeof(b));    memset(c,0,sizeof(c));    memset(d,0,sizeof(d));cin>>n2>>k2;int flag2=0;for(int i=1;i<=n2;i++){cin>>xx>>yy;a[xx]++;b[yy]++;c[100000+xx-yy]++;d[200000-xx-yy]++;if(flag2==1) continue;if(a[xx]>=k2||b[yy]>=k2)     {cout<<i<<endl; flag2=1;}if(c[100000+xx-yy]>=k2||d[200000-xx-yy]>=k2)     {cout<<i<<endl; flag2=1;}}if(!flag2) cout<<-1<<endl;/*The relationship between the number of oblique rows and the mushroom coordinates can be obtained by mathematics}return 0;



























How to get into personal habits

I took the diagonal as line 100000 */ 

A very embarrassing question;

The point is to clear all data in the middle;

I saw the long-lost memset again;

It is good to understand;

end...

4> Bull language;

Or just changed the question;

Very speechless brainless basic string questions;

Above topic:

【Problem Description】

The cows heard that the pig had invented a secret language called "Pig Language", because the pig didn't want the owner Xiao Huang to know what they were discussing. The cows also felt it was very good, so they wanted to invent their own language, the cow language .. It's easy to convert a normal English word to Ox. If a word starts with a vowel ('a','e','i','o','u), then just add this Add "cow" to the end of the word. For example, "udder" needs to become "uddercow"; if the first letter of a word is not a vowel, then just put the first letter of the word at the end of the word, Then add "ow" at the end. For example "farmer" needs to become "armerfow". So "the cowsescape at dawn" becomes "hetow owscow escapecowatcow awndow." Huang knows about their "prison break" plan. Unfortunately, the cows are not linguists, they find this kind of translation too boring, so the task is left to you. You need to translate N (1 ≤ N ≤ 100) English words Translated into Cow, the word length is between 3 and 40.

 

【enter】

Line 1: An integer N.

Lines 2 to N+1: One word per line

 

【Output】

Lines 1 to N, each line has a corresponding cow language word.

 

[Input and output example 1]

latin.in

latin.out

5

udder

farmer

milk

aaa

zzz

uddercow

armerfow

ilkmow

aaacow

zzzow

 

However;

When Xun Yu did it for the first time, he made two bids! ! !

(emmmmm black question mark?!)

Afterwards, my mind became clear and I figured it out;

It's okay to open an array to the string;

Just enter it directly;

Then open an array in each word;

Look at the table below to judge and there is no problem;

Open a for loop when outputting;

ojbk is output from the second letter;

Above code:

#include<bits/stdc++.h>

using namespace std;
string a;
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
    if(a[0]=='a'||a[0]=='e'||a[0]=='i'||a[0]=='o'||a[0]=='u')
        cout<<a<<"cow"<<endl;
    else
    { for(int j=1;j<a.size();j++)     cout<<a[j];     cout<<a[0]<<"ow"<<endl;     } }         return 0;
   
   
   



}

brainless input

无脑判断;

无脑输出;

就是这么干脆;

end...

最后再总结一下吧;

虽然说这次考试没有完整的参与;

但是题目都是看了一遍的;

发现自己还是存在很多不足的;

刷题的时候太水;

导致基础不是很扎实;

下一阶段减少刷题量;

提高质量吧;

再把基础的东西好好看一看补一补;

以前做过的题在自己敲一遍;

老母猪可能是真的要停经了;

但是;

以后不仅回生还会养了呀!!!

荀彧同学fighting吧;

全文终。

Guess you like

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