Goodbye 2019

Goodbye 2019

The game in the morning, and thus did not play. Open to reproduce, A out of three questions, which is probably my level right now

A. Card Game

Simple questions to see who the biggest brand

#include<bits/stdc++.h>
using namespace std;
int a[105],b[105];
int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n,k1,k2;
        cin >> n >> k1 >> k2;
        for(int i = 0;i<k1;i++)
        {
            cin >> a[i];
        }
        for(int i =0;i<k2;++i)
            cin >> b[i];
        bool flag = false;
        for(int i = 0;i<k1;++i)
        {
            if(a[i]==n)
            {
                flag = true;
                break;
            }
        }
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

 

B. Interesting Subarray

Simple question, the idea is to compare two adjacent numbers, if the difference > 1 , which is consistent with the meaning of the questions on behalf of the solution, if not, the solution does not exist to prove the entire array.

 

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int num[maxn];
int main()
{
   int T;
   cin >> T;
   while(T--)
   {
       int n;
       cin >> n;
       for(int i = 0;i<n;i++)
       {
           cin >>num[i];
       }
       bool flag = false;
       int l = 0,r = 0;
       for(int i =0;i<n-1;i++)
       {
           if(abs(num[i]-num[i+1])>1)
           {
               flag =true;
               l = i,r = i+1;
               break;
           }
       }
       if(!flag)
            printf("NO\n");
       else
       {
           printf("YES\n");
           printf("%d %d\n",l+1,r+1);
       }
 
 
   }
    return 0;
}

 

 

 

C. Make Good

Simple questions, we first calculated the left hand side, referred to as A , calculated on the right, referred to as B , according to the nature of XOR, add a number Xianxiang array B , the left side becomes A + B , into the right 0 , then add the number of A + b , you can meet the meaning of the questions, these two numbers is ask.

 

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;
LL num[maxn];
int main()
{
  int T;
  cin >>T;
  while(T--)
  {
      int n;
      cin >> n;
      for(int i = 0;i<n;++i)
      {
          cin >> num[i];
      }
      LL ans = num[0],ans2 = num[0];
      for(int i = 1;i<n;i++)
      {
          ans+=num[i];
          ans2^=num[i];
      }
      if(ans == ans2*2)
      {
          printf("0\n\n");
      }
      else
      {
          cout << 2 << endl;
          cout << ans2 << " " << ans+ans2 << endl;
      }
  }
    return 0;
}

 

 

 

Ps:   The following explanations are from cf the official explanations of

D. Strange Device

Interactive title, this is my first time doing interaction problems, very ignorant, did not understand the question.

Meaning of the questions: to give you a n -element array A , and to ensure that one of the elements pairwise disjoint, you have a machine, the machine accepts input k positions entered return in this k subsequent bits of the number of sorted m-th number in a position where his values. Let you pass no more than n times asked to calculate the m size.

Ideas:

Query stable k + 1 times, each time with a first k + 1 number of replacements of 1-k + 1 a number, provided 1-k + 1 of the m-th large number of A , the first m + 1-th to b, by the clear meaning of the questions, b appears m times a occurs k + 1-m times, therefore, the value returned for each query records, the largest of which is b , the record about b the number of occurrences that can be calculated m

 

#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
 
    int n, k;
    cin>>n>>k;
    vector<int> elements;
    for (int i = 1; i<=k+1; i++)
    {
        cout<<"? ";
       
        for (int j = 1; j<=k+1; j++) if (j!=i) cout<<j<<' ';
        cout<<endl;
       
        int pos, el;
        cin>>pos>>el;
        elements.push_back(el);
    }
    int maxx = elements[0];
    for (auto it: elements) maxx = max(maxx, it);
    int m = 0;
    for (auto it: elements) if (it==maxx) m++;
    cout<<"! "<<m<<endl;
 
}

 

 

 

E. Divide Points

The meaning of problems: point set is divided into two parts will, provided the distance between any two points belonging to the same part as set A , the distance between any two points belonging to different parts of the set B , wherein a requested output set meet the meaning of the title.

Ideas: we can be divided according to the parity point A 00 , A 01 , A 10 , A 11 these four categories, consider the first classification if A 00 + A 11 > 0 && A 01 + A 10 > 0 we can prove collection a number is an even number in the entire collection B numbers are all odd, if not the first classification type, the rest are all proved a 00 and a . 11 , or all , a 01 , a 10 may be a second species classification, if it is the first case it can be shown that the set of a are all divisible 4, set B in addition to all 4 I 2 number, if it is the second case, it may prove set a of all divisible 4,Set B in addition to all 4 I 2 numbers. If the second classification is not true, then a proof of the four cases under current conditions there is only so we can find out which category they belong point, and for the coordinate transformation at this point on, repeat the above operation, until a solution is found.

 

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
struct Node
{
    int x,y;
    Node(int _x = 0,int _y = 0):x(_x),y(_y) {}
};
Node Point[maxn];
int cnt[3][3]  = {0};
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i<n; i++)
    {
        scanf("%d %d",&Point[i].x,&Point[i].y);
        Point[i].x+=int(1e6);
        Point[i].y+=int(1e6);
    }
    while(true)
    {
        memset(cnt,0,sizeof(cnt));
        for(int i = 0; i<n; ++i)
        {
            int x = Point[i].x,y = Point[i].y;
            ++cnt[x%2][y%2];
        }
        if(cnt[0][0]+cnt[1][1]>0&&cnt[0][1]+cnt[1][0]>0)
        {
            printf("%d\n",cnt[0][0]+cnt[1][1]);
            int cur = 0;
            for(int i = 0; i<n; i++)
            {
                int x = Point[i].x,y = Point[i].y;
                if((x%2==0&&y%2==0)||(x%2==1&&y%2==1))
                {
                    if(cur==0)
                        printf("%d",i+1);
                    else
                        printf(" %d",i+1);
                    ++cur;
                }
            }
            return 0;
        }
        if(cnt[0][0]+cnt[1][0]>0&&cnt[1][1]+cnt[0][1]>0)
        {
            printf("%d\n",cnt[0][0]+cnt[1][0]);
            int cur = 0;
            for(int i = 0; i<n; i++)
            {
                int x = Point[i].x,y = Point[i].y;
                if((x%2==0&&y%2==0)||(x%2==1&&y%2==0))
                {
                    if(cur==0)
                        printf("%d",i+1);
                    else
                        printf(" %d",i+1);
                    ++cur;
                }
            }
            return 0;
        }
        int x = 0;
        int y = 0;
        for(int i = 0; i<2; ++i)
        {
            for(int j = 0; j<2; ++j)
            {
                if(cnt[i][j])
                {
                    x = i;
                    y = j;
                    break;
                }
            }
        }
        for(int i = 0; i<n; i++)
        {
            Point[i].x = (Point[i].x-x)/2;
            Point[i].y = (Point[i].y-y)/2;
        }
        // return p;
    }
 
 
    return 0;
}

 

 

 

G.Subset with Zero Sum

The change in expression can be obtained . 1 <IA = I <= n- , we can be converted to a directed graph, for each point I , are connected to an edge point ( IA I ) , and finally we can in this FIG. to find on a ring. Sum of all points on this ring is necessarily 0 , the equation can be listed to prove.

 

#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1;i<=n;++i)
        cin >> a[i];
    vector<bool> visited(n+1);
    int cur = 1;
    while(!visited[cur])
    {
        visited[cur] = true;
        cur = cur -a[cur];
    }
    vector<int> ans = {cur};
    int cur1 = cur - a[cur];
    while(cur1!=cur)
    {
        ans.push_back(cur1);
        cur1 = cur1-a[cur1];
    }
    cout << ans.size() << '\n';
    for(auto it:ans) cout << it << " ";
    cout << '\n';
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int t;
    cin >> t;
    for(int i = 0;i<t;i++)
        solve();
    return 0;
}

Guess you like

Origin www.cnblogs.com/baihualiaoluan/p/12167579.html