From a0890b9dd977b0f4e724f17adf65d50311cd4885 Mon Sep 17 00:00:00 2001 From: Nabil Silva Date: Fri, 30 Oct 2015 02:52:00 +0530 Subject: [PATCH 1/3] Better Soln --- CANDY.cpp | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/CANDY.cpp b/CANDY.cpp index 077dbfe..867173b 100644 --- a/CANDY.cpp +++ b/CANDY.cpp @@ -1,31 +1,32 @@ -/* -USER: zobayer -TASK: CANDY -ALGO: ad-hoc -*/ +#include -#include +using namespace std; int main() -{ - int a[10001], n, i, avr, sum, total; - while(scanf("%d", &n) == 1 && n > 0) - { - for(i=sum=0; i < n; i++) - { - scanf("%d", &a[i]); - sum += a[i]; - } - if(sum % n == 0) - { - avr = sum / n; - for(i=total=0; i < n; i++) - if(a[i] < avr) - total += avr - a[i]; - printf("%d\n", total); - } - else printf("-1\n"); - } - return 0; -} +{ int a[10001]; + int n; + int i; + int s=0; + while(1) + { + i=0; + s=0; + cin>>n; + int t=n; + if(n==-1) break; + while(t--) + { + int x; + cin>>x; + a[i++]=x; + s+=x; + } + if(s%n!=0) cout<<-1<0) o += a[k] - (s/n); + cout< Date: Fri, 30 Oct 2015 04:52:03 +0530 Subject: [PATCH 2/3] Improved algorithm --- FCTRL2.cpp | 79 +++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 46 deletions(-) mode change 100644 => 100755 FCTRL2.cpp diff --git a/FCTRL2.cpp b/FCTRL2.cpp old mode 100644 new mode 100755 index 5a10923..9ca7427 --- a/FCTRL2.cpp +++ b/FCTRL2.cpp @@ -1,49 +1,36 @@ -/* -USER: zobayer -TASK: FCTRL2 -ALGO: math, big integer -*/ - -#include -#include - -#define MAXDIGIT 101 -#define MAXLENGTH 159 - -using namespace std; - -char factorial[MAXDIGIT][MAXLENGTH]; - -void multiply(int k) -{ - int carry = 0, sum, i = 0, len = strlen(factorial[k-1]); - while(i0) - { - factorial[k][i++] = (carry%10) + '0'; - carry/=10; - } -} - +#include int main() { - int n, k, len, t; - factorial[0][0]='1'; factorial[1][0]='1'; - for(k=2;k=0;k--) - printf("%c",factorial[n][k]); - printf("\n"); - } - return 0; -} + int t; + int a[200]; //array will have the capacity to store 200 digits. + int n,i,j,temp,m,x; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + a[0]=1; //initializes array with only 1 digit, the digit 1. + m=1; // initializes digit counter + + temp = 0; //Initializes carry variable to 0. + for(i=1;i<=n;i++) + { + for(j=0;j0) //while loop that will store the carry value on array. + { + a[m]=temp%10; + temp = temp/10; + m++; // increments digit counter + } + } + for(i=m-1;i>=0;i--) //printing answer + printf("%d",a[i]); + printf("\n"); + } + return 0; +} From b7d924d41a962ed1ba30a5835db957f5ad0f0c51 Mon Sep 17 00:00:00 2001 From: Sailesh Sriram Date: Fri, 30 Oct 2015 22:23:53 +0530 Subject: [PATCH 3/3] EGYPIZZA Updated --- EGYPIZZA.cpp | 112 ++++++++++----------------------------------------- 1 file changed, 22 insertions(+), 90 deletions(-) mode change 100644 => 100755 EGYPIZZA.cpp diff --git a/EGYPIZZA.cpp b/EGYPIZZA.cpp old mode 100644 new mode 100755 index 7ca6f96..607750a --- a/EGYPIZZA.cpp +++ b/EGYPIZZA.cpp @@ -1,92 +1,24 @@ -/* -USER: zobayer -TASK: EGYPIZZA -ALGO: ad-hoc -*/ - -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#define READ(f) freopen(f, "r", stdin) -#define WRITE(f) freopen(f, "w", stdout) -#define ALL(c) c.begin(), c.end() -#define PB(x) push_back(x) -#define UB(s, e, x) upper_bound(s, e, x) -#define LB(s, e, x) lower_bound(s, e, x) -#define REV(s, e) reverse(s, e); -#define SZ(c) c.size() -#define SET(p) memset(p, -1, sizeof(p)) -#define CLR(p) memset(p, 0, sizeof(p)) -#define MEM(p, v) memset(p, v, sizeof(p)) -#define i64 long long -#define ff first -#define ss second -#define DEBUG if(0) - -template< class T > T sq(T x) { return x * x; } -template< class T > T abs(T n) { return (n < 0 ? -n : n); } -template< class T > T max(T a, T b) { return (!(a < b) ? a : b); } -template< class T > T min(T a, T b) { return (a < b ? a : b); } -template< class T > T gcd(T a, T b) { return (b != 0 ? gcd(b, a%b) : a); } -template< class T > T lcm(T a, T b) { return (a / gcd(a, b) * b); } -template< class T > T mod(T a, T b) { return (a < b ? a : a % b); } -template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; } -template< class T > void setmax(T &a, T b) { if(a < b) a = b; } -template< class T > void setmin(T &a, T b) { if(b < a) a = b; } - -const int MAX = 10001; +#include + +using namespace std; + +int main() +{ + int n; + cin>>n; + char *a = new char[n*3+1]; + char b[3]; + for(int i=0; i>b; + strcpy(&a[i*3],b); + } + for(int i=0; i> 1); - cnt12 &= 1; - if(cnt12) ans++, cnt14 -= 2, setmax(cnt14, 0); - - // for 1/4 - ans += ((cnt14 + 3) >> 2); - - printf("%d\n", ans); - return 0; -} + + return 0; +}