From cdbe07d263de1727c918e4661261402b0ae790f4 Mon Sep 17 00:00:00 2001 From: AtiaBabaBa <62164180+AtiaBabaBa@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:42:19 +0700 Subject: [PATCH] Please commit changes, Thank you. #Hacktoberfest --- Binary Search/Cat/Cat.txt | 63 +++++++++++++++++++++++++++++ Binary Search/Cat/Sol.cpp | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 Binary Search/Cat/Cat.txt create mode 100644 Binary Search/Cat/Sol.cpp diff --git a/Binary Search/Cat/Cat.txt b/Binary Search/Cat/Cat.txt new file mode 100644 index 0000000..efc943a --- /dev/null +++ b/Binary Search/Cat/Cat.txt @@ -0,0 +1,63 @@ +This problem from TOI13 (Thailand Olympaid of Informatics 2017). +I love this problem because I love Cats. + +Source: https://www.proprog.ml/tasks/toi13_cat/descs/12575 + +Time Limit 1000 ms +Memory Limit 512 MB + +N cats stay in line. N is always even because we want to pair the cats which have the same height in +the consecutive position(Each value of height can have only 1 pair). But the cats stay in a random position. +It is your task to find the size of the pocket to bring the cats and move it to the right position. + +For Example: +N = 6 (6 cats) +Cat height = 3 3 2 5 5 2 +We can see that the cats that height equals to 3 and 5 already each with the couple but the cats that +height equals to 2 didn't sit near to each other. +So, we will use the pocket that has the size of 2 to bring the two-unit-height cat to sit next to each other. +It'll become 3 3 2 2 5 5 or 3 3 5 5 2 2. + +Input: +1st line contains amount of N while 1<=N<=2x10^6 or 2000000 +Next N lines is hi stands for the height of cat number i while 1<=i<=N and 1<=hi<=2^31 +Output: +The smallest size of pocket that can rearrange all cat to the right position. + +Example input1: +6 +3 +3 +2 +5 +5 +2 +Example output1: +2 +(Like an example) + +Example input2: +6 +3 +5 +2 +2 +5 +3 +Example output2: +3 +(Use pocket size 3 to bring 2 and 3 cats sit next to each other it'll become 5 5 3 3 2 2 for example) + +Example input3: +6 +2 +2 +3 +3 +5 +5 +Example output3: +0 +(Doesn't need to use the pocket) + + diff --git a/Binary Search/Cat/Sol.cpp b/Binary Search/Cat/Sol.cpp new file mode 100644 index 0000000..60e3a8c --- /dev/null +++ b/Binary Search/Cat/Sol.cpp @@ -0,0 +1,84 @@ +#include +using namespace std; +vector v; +long long int l=0,r=0,mid,big; +int unpair; +long long int data[2000009]; +int main() +{ + int n; + scanf(" %d",&n); + long long int a; + for(int i=0;i