Codeforces Round #312 (Div. 2) ABC

Source: Internet
Author: User
Tags bitset integer division cmath

"Match link" click here~~

A. Lala Land and Apple Trees:

"Test Instructions":

Amr lives in Lala land. Lala Land is a very beautiful country, located in the coordinate line. Lala land is increasingly ubiquitous with famous apple trees.

Lala Land happens to be n apple trees. The number of trees I was in position XI and Apple with artificial intelligence can grow. AMR wants to collect apples from apple trees. AMR is currently maintained in the X =0 position. At the beginning, he can choose whether to go to the left or right. He would go on in his direction until he met an apple tree, which he had not visited before. He would take all the apples and then twist his direction and go on in this direction until he met another apple tree that he had not visited before. In other words, AMR accesses every new apple tree as it reverses his direction. AMR will stop collecting apples when there are no more trees and he also does not visit in the direction he faces.
The maximum number he can collect?

Code:

#ifndef _glibcxx_no_assert#include <cassert> #endif # include <cctype> #include <cerrno> #include < cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio># Include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103l#include < ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool># Include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif//C + + #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception># Include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd > #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new># Include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream># Include <stack> #include <stdexcept> #include <streambuf> #include <string> #include < typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103l# Include <array> #include <atomic> #include <chrono> #include <condition_variable> #include < forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random > #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error># Include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include < unordered_map> #include <unordered_set> #endifusing namespace std; #define REP (i,j,k) for (int i= (int) j;i< (int) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define LOWBIT (a) A&-a#define Max (A, b) A>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef long Long ll;typedef unsigned long Long llu;typedef double db;const int n=1e6+10;int I,j,n,m,t,ans,res,cnt,tmp;char str[n];bool vis[n];int nx[N],ny[N];int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; struct node{int x, y;}; vector< pair<int,int> >ll,rr;bool cmp1 (pair<int, int >a,pair <int, int >b) {return a.first>b . First;} BOOL Cmp2 (pair<int, int >a,pair <int, int >b) {return a.first<b.first;}        int main () {while (cin>>n) {int x,a;            Rep (i,0,n) {cin>>x>>a;            if (x<0) Ll.push_back (Make_pair (x,a));        Else Rr.push_back (Make_pair (x,a));        } sort (Ll.begin (), Ll.end (), CMP1); Sort (Rr.begin (), Rr.end (), CMP2);        int res=0;        int lenl=ll.size (), lenr=rr.size ();                if (LENL==LENR) {rep (i,0,lenl) {res+=ll[i].second;            Res+=rr[i].second;            }} else if (LENL&LT;LENR) {for (int i=0; i<lenl; ++i) Res+=ll[i].second;        for (int i=0; i<=lenl; ++i) Res+=rr[i].second;            } else {for (int i=0; i<=lenr; ++i) Res+=ll[i].second;        for (int i=0; i<lenr; ++i) Res+=rr[i].second;    } cout<<res<<endl; } return 0;}

B. AMR and the Large Array

"Test Instructions":

Amr got a large array of size n. AMR does not like large arrays, so he intends to narrow it down.

Amr doesn't care unless it's beautiful in array of anything. The beauty of the array is defined as the maximum number of times that some numbers occur in this array. He wants to choose this array so that its beauty will be the same as the smallest sub-segments in the original array.

Help Amr by selecting the smallest child segment.

Code:

#ifndef _glibcxx_no_assert#include <cassert> #endif # include <cctype> #include <cerrno> #include < cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio># Include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103l#include < ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool># Include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif//C + + #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception># Include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd > #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new># Include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream># Include <stack> #include <stdexcept> #include <streambuf> #include <string> #include < typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103l# Include <array> #include <atomic> #include <chrono> #include <condition_variable> #include < forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random > #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error># Include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include < unordered_map> #include <unordered_set> #endifusing namespace std; #define REP (i,j,k) for (int i= (int) j;i< (int) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define LOWBIT (a) A&-a#define Max (A, b) A>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef long Long ll;typedef unsigned long Long llu;typedef double db;const int n=1e6+10;int I,j,n,m,t,ans,res,cnt,tmp;char str[n];bool vis[n];int nx[N],ny[N];int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; struct node{int x, y;}; BOOL Cmp1 (node A,node b) {return a.x<b.x;}    pair<int,int> num [n];int c[n];int pre[n];int last[n];int maxxa=-1;int maxxb=-1;int Main () {cin>>n;        Rep (i,0,n) {cin>>j;        ++C[J]; Maxxa=max (Maxxa,c[j]);////Find out the number of occurrences of the most Maxxb=max (MAXXB,J);///The maximum if (c[j]==1) {Pre[j]=last            [j]=i;///Pre[1]=last[1]=1} else {pre[j]=min (pre[j],i);        Last[j]=max (Last[j],i); }//cout<< "pre[j]= "<<j<<" <<pre[j]<<endl;    cout<< "last[j]=" <<j<< "" <<last[j]<<endl;    }//cout<<maxxa<<endl;///3//COUT&LT;&LT;MAXXB&LT;&LT;ENDL;///2 int fx=-1,fy=n;                for (int i=0; i<=maxxb; ++i) {if (C[I]==MAXXA) {if (last[i]-pre[i]<fy) {                Fx=pre[i];            Fy=last[i]-pre[i];    }}} cout<<fx+1<< "" <<fx+fy+1; return 0;}

C. AMR and Chemistry

Test instructions

AMR loves chemistry and specializes in experiments. He is preparing a new and interesting experiment.

AMR has n different types of chemicals. Each chemical I has the initial volume of the Ascension. For the experiment, AMR has mixed all the chemicals together, but all the chemical volumes must be equal to the first bit. Therefore, his task is to make all the chemical quantity equal.

To do this, AMR can do two different things.

Select some chemistry I and a current volume so that the new volume will be 2AI
Select some chemistry I and divide the volume by 2 (integer division) so that the new volume will
Assume that each chemical is contained in an infinite number of containers. Now AMR want to know what the operation is, so that all chemical volumes are equal to the minimum required number of people?

Code:

#ifndef _glibcxx_no_assert#include <cassert> #endif # include <cctype> #include <cerrno> #include < cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio># Include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103l#include < ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool># Include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif//C + + #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception># Include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd > #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new># Include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream># Include <stack> #include <stdexcept> #include <streambuf> #include <string> #include < typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103l# Include <array> #include <atomic> #include <chrono> #include <condition_variable> #include < forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random > #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error># Include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include < unordered_map> #include <unordered_set> #endifusing namespace std; #define REP (i,j,k) for (int i= (int) j;i< (int) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define LOWBIT (a) A&-a#define Max (A, b) A>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) #define DEBUG (x) cerr<< #x << "=" <<x<<endl; #define FF first#define SS second#define PB push_back#define MP make_pairtypedef Long Long Ll;co NST ll Inf=1<<28;const ll linf=1ll<<61;//my own input/output stream#define geti (x) x=getnum () #define GETII (x , y) Geti (x), Geti (y) #define GETIII x, Z, getii (x, y), Geti (z) #define PUTI (x) putnum (x), PUTSP () #define PUTII (y) Puti ), Putnum (y), putsp () #define PUTIII (x, z) putii (x, y), Putnum (z), PUTSP () #define PUTSI (×) putnum (x), Putendl () #define    Putsii (x, y) Puti (×), Putnum (y), Putendl () #define PUTSIII (x, Y, z), Putii (y) Putnum (), and Putendl () inline ll getnum () {    Register ll R=0;    register bool ng=0;    Register char c;    C=getchar (); while (c!= '-' && (c< ' 0 ' | |    C> ' 9 ')) C=getchar ();    if (c== '-') Ng=1,c=getchar (); while (c!= "&&c!= ' \ n ') r=r*10+c-' 0 ', C=getchar ();    if (NG) r=-r; return r;}    Template <class t> inline void Putnum (T x) {if (x<0) Putchar ('-'), x=-x;    Register short a[20]= {},sz=0;    while (x>0) a[sz++]=x%10,x/=10;    if (sz==0) Putchar (' 0 '); for (int i=sz-1; i>=0; i--) Putchar (' 0 ' +a[i]);} inline void putsp () {Putchar (");} inline void Putendl () {putchar (' \ n ');}    inline char Mygetchar () {register char c=getchar (); while (c== ' | |    c== ' \ n ') C=getchar (); return c;} typedef long Long Ll;typedef unsigned long long llu;typedef double db;const int n=1e6+10;int i,j,n,m,t,ans,res,cnt,tmp;ch Ar str[n];bool vis[n];int nx[n],ny[n];int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};int dir8[8][2]= {{1,0},{1,1},{0,1}, { -1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};struct node{int x, y;}; BOOL Cmp1 (node A,node b) {return a.x<b.x;} pair<int,int> num [n];int c[n];int pre[n];int last[n];int maxxa=-1;int maxxb=-1;int a[N],b[N];vector <bool> V[n],vans;int Main () {scanf ("%d", &n);   int kk=20;        for (int i=1; i<=n; i++) {scanf ("%d", &a[i]);        Int J;                for (j=1; j<20; J + +) {if ((a[i]>> (j-1)) >0&& (a[i]>>j) ==0) {            Break }} for (int k=j-1; k>=0; k--) {v[i].        PB ((a[i]>>k) &1);    } kk=min (Kk,int (V[i].size ()));        } for (int i=0; i<kk; i++) {bool ok=1;                for (int j=1; j<n; J + +) {if (V[j][i]!=v[j+1][i]) {ok=0;            Break }} if (OK) vans.        PB (V[1][i]);    else break;        } for (int i=1; i<=n; i++) {int j=vans.size ();            while (J<v[i].size () &&v[i][j]==0) {b[i]++;        j + +;    }} int ans=99999999999;        for (int i=0; I<30-int (Vans.size ()); i++) {int tans=0; for (int j=1; j<=n; J + +) {Tans+=int (V[j].size ())-INT (Vans.size () +min (i,b[j)) +max (0,i-b[j]);    } ans=min (Ans,tans);    } printf ("%d\n", ans); return 0;}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round #312 (Div. 2) ABC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.