Friday, November 11, 2016

Uva 102 - Ecological Bin Packing

#include <iostream>
#include <string>
using namespace std;
int main (void) {
unsigned int bottles[9];
int bcg[9],bgc[9],cbg[9],cgb[9],gcb[9],gbc[9],i;
while (cin >> bottles[0]) {
int sum1=0,sum2=0,sum3=0,sum4=0,sum5=0,sum6=0;
string minimum = "BGC";
for ( i = 1; i < 9; i++) {
cin >> bottles[i];
bcg[i]=bottles[i],bgc[i]=bottles[i];
cgb[i]=bottles[i],cbg[i]=bottles[i];
gcb[i]=bottles[i],gbc[i]=bottles[i];
     }
bcg[0]=0,bgc[0]=0,bcg[5]=0,bcg[7]=0,bgc[4]=0,bgc[8]=0;
cbg[0]=bottles[0],cgb[0]=bottles[0],cbg[2]=0,cbg[3]=0;cbg[7]=0,cgb[2]=0,cgb[6]=0,cgb[4]=0;
gcb[0]=bottles[0],gbc[0]=bottles[0],gbc[8]=0,gcb[1]=0,gcb[5]=0,gcb[6]=0,gbc[1]=0,gbc[3]=0;
unsigned int min = 1 << 31;
for( i = 0 ; i < 9 ; i++ ) sum1+=bcg[i],sum2+=bgc[i],sum3+=cbg[i],sum4+=cgb[i],sum5+=gbc[i],sum6+=gcb[i];
if (sum1 < min)minimum = "BCG",min = sum1;
if (sum2 < min)minimum = "BGC",min = sum2;
if (sum3 < min)minimum = "CBG",min = sum3;
if (sum4 < min)minimum = "CGB",min = sum4;
if (sum5 < min)minimum = "GBC",min = sum5;
if (sum6 < min)minimum = "GCB",min = sum6;
cout  <<  minimum  <<  " " <<  min  <<  endl;
}
return 0;
}

Uva 10194 - Football (aka Soccer)

/*                                                                 CODEMAN
                                                                  Arif Khan Nihar
                                                     Uva 10194 - Football (aka Soccer)
                                                                date -> 22/10/2016

*/
#include<bits/stdc++.h>
using namespace std;
int match_result(int a,int b){
     if(a  > b) return 1;
     else if(a == b) return 0;
     else return -1;
}

struct match_records{
            string t_name;
            string t_name_uppercase;
            int t_points,t_goal,t_w,t_t,t_l,t_g_eat,t_p_m;

    }team_records[51];

string oneTotwo(string s){
    size_t p;string s1;
    p = s.find('#');
    s1 = s.substr(0,p);
    return s1;
}

string oneTotwore(string s){
    reverse(s.begin(),s.end());
        size_t p;string s1;
        p = s.find('#');
        s1 = s.substr(0,p);
        reverse(s1.begin(),s1.end());
       return s1;
}

int value(string s1){
    size_t p;string s2;
    p = s1.find('#');
    s2 = s1.substr(1+p);
    int n = 0;
    istringstream(s2) >> n;
    return n;
}

int value1(string s1){
    size_t p;string s2;
    p = s1.find('#');
    s2 = s1.substr(0,p);
    int n = 0;
    istringstream(s2) >> n;
    return n;
}

int check(string a,int n){
    int k = 0;
    for(int i = 0; i < n ; i++ ){
        if(a == team_records[i].t_name){
            k = i;
            break;
        }
    }
   return k;
}

bool cmp(const match_records &x, const match_records &y){

  if (x.t_points != y.t_points)
       return x.t_points > y.t_points;

  if (x.t_w!= y.t_w)
       return x.t_w > y.t_w;

  if (x.t_goal - x.t_g_eat != y.t_goal - y.t_g_eat)
       return x.t_goal - x.t_g_eat > y.t_goal - y.t_g_eat;

  if (x.t_goal != y.t_goal)
       return x.t_goal > y.t_goal;

  if (x.t_p_m != y.t_p_m)
       return x.t_p_m < y.t_p_m;

  return x.t_name_uppercase < y.t_name_uppercase;

}

int main()
{

  int n,t_num,i,j,t_m_num;
  string touranment_name,team_name;
  string s2,s3;char ss[101];
  size_t p , p1;

  cin >> n;
  cin.ignore(101,'\n');
  while(n--){
    getline(cin,touranment_name);
    cin >> t_num;
    cin.ignore(101,'\n');

    for( i = 0 ; i < t_num ; i++ ) {
         getline(cin,team_records[i].t_name);
         team_records[i].t_name_uppercase = team_records[i].t_name;
         transform(team_records[i].t_name.begin(),team_records[i].t_name.end(),team_records[i].t_name_uppercase.begin(),:: toupper);
    }

    cin >> t_m_num;
    cin.ignore(101,'\n');

    for( i = 0 ; i < t_m_num ; i++ ){
        getline(cin,s2);

        p = s2.find('@');
        s3 = s2.substr(0,p);
        s2 = s2.substr(p+1);

        string f_t_n = oneTotwo(s3);
        string s_t_n = oneTotwore(s2);

        int f_t_g_n = value(s3);
        int s_t_g_n = value1(s2);

        int k1 = 0;
        k1 = check(f_t_n,t_num);
        team_records[k1].t_p_m ++;

        int k2 = 0;
        k2 = check(s_t_n,t_num);
        team_records[k2].t_p_m ++;

    team_records[k1].t_goal += f_t_g_n;
    team_records[k1].t_g_eat += s_t_g_n;
    team_records[k2].t_goal += s_t_g_n ;
    team_records[k2].t_g_eat += f_t_g_n;

    if(match_result(f_t_g_n,s_t_g_n)>0){
        team_records[k1].t_w += 1;
        team_records[k1].t_points +=3;
        team_records[k2].t_l +=1;
    }
    else if(match_result(f_t_g_n,s_t_g_n)==0){
        team_records[k1].t_t +=1;
        team_records[k2].t_t +=1;
        team_records[k1].t_points +=1;
        team_records[k2].t_points +=1;
    }
    else{
        team_records[k2].t_w += 1;
        team_records[k2].t_points +=3;
        team_records[k1].t_l +=1;
      }
   }
    stable_sort(team_records,team_records+t_num,cmp);

    cout<    for (int i = 0; i < t_num; i++) {
      cout << i+1 << ") " << team_records[i].t_name << " " << team_records[i].t_points << "p, " << team_records[i].t_p_m << "g (" << team_records[i].t_w << "-" << team_records[i].t_t << "-" << team_records[i].t_l << "), " << team_records[i].t_goal - team_records[i].t_g_eat << "gd (" << team_records[i].t_goal << "-" << team_records[i].t_g_eat << ")" << endl;
      team_records[i].t_name.clear(),team_records[i].t_points = 0,team_records[i].t_p_m = 0,team_records[i].t_w = 0,team_records[i].t_t = 0,team_records[i].t_goal = 0,team_records[i].t_l = 0,team_records[i].t_g_eat = 0;
    }

   if(n)cout << endl;
  }

    return 0;
}































































































































uva 10127 - Ones

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,c;
while(scanf("%d",&n)==1) {
m=c=1;
while(m!=0) {
m = m*10 + 1;
m%=n;
c++;
        }
cout << c << endl;
    }
return 0;
 }

uva 10114 - Loansome Car Buyer

#include<bits/stdc++.h>
using namespace std;
int main() {
int d,d_n,m,re;
double d_p, l,dp[101],d1,l_d,c_l;
while (cin >> d >> d_p >> l >> d_n && d>=0) {
re=l_d=c_l=0;
while (d_n--) {
cin >> m >> d1;
for ( int i = m ; i < 101 ; i++ )
dp[i] = d1;
}
l_d = l / d,c_l = (d_p + l) * (1 - dp[0]);
while (c_l < l)
re++,l -= l_d,c_l = c_l * (1 - dp[re]);
if (re == 1) cout << "1 month" << endl;
else cout << re << " months" << endl;
     }
return 0;
  }

Uva 10110 - Light, more light

#include<bits/stdc++.h>
using namespace std;
int main()
{
unsigned long n,k;
while(cin >> n  && n ) {
k = (int)sqrt(n);
if (k*k==n)  printf("yes\n");
else  printf("no\n");
       }
return 0;
    }

Uva 10107 - What is the Median?

#include<bits/stdc++.h>
using namespace std;
#define maxN 10001
int main()
{
int n = 0, a[maxN];

while (scanf("%d", &a[++n])!=EOF) {

for ( int  i = n-1 ;  i >= 1 ;  i-- )
if (a[i] > a[i+1])  swap(a[i], a[i+1]);
else break;
if (n%2) printf("%d\n", a[(n+1)/2]);
else printf("%d\n", (a[n/2] + a[n/2+1])/2);

             }

return 0;
 }



Thursday, November 10, 2016

Uva 10082 - WERTYU

#include<bits/stdc++.h>
using namespace std;
int main()
{
string u_key ="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
int n,i,j;
char ch;
size_t p;
while(cin.get(ch)) {
if(ch==32 || ch == '\n')  cout << ch;
else {
p = u_key.find(ch) ;
cout  <<  u_key[p-1] ;
       }
    }
return 0;
  }

Uva 10071 - Back to High School Physics

#include <iostream>
using namespace std;
int main() {
int v,t;
while(cin >> v >> t) {
cout  <<  2*v*t  <<  endl;
}
return 0;
}

Uva 10055 - Hashmat the Brave Warrior

#include<iostream>
using namespace std;
int main()
{
unsigned long x,y;
while(cin >> x >> y){
if(y>x) cout << y-x << endl;
else cout << x-y << endl;
}
return 0;
}

Uva 10050 - Hartals

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,j,i,k,l,p,l1=0;
cin>>n;
while(n--) {
cin >> m >> p;
int ad[m],bd[p];
for( i = 1 ; i <= m ; i++ ) ad[i]=0 ;
for( i = 1 ; i<= p ; i++ ) cin >> bd[i] ;
for( i = 1 ; i <=p ; i++ )
for( j = bd[i] ;  j <=m ; j += bd[i] )
ad[j]=1;
l=0;
for( i = 1 ; i <=m ; i++ )
if(ad[i]==1 && (i-6)%7!=0 && i%7!=0)l++;
cout << l << endl ;
     }
return 0;
   }

Uva 10041 - Vito's Family

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i,j,ad[501],k;
vector<int>v;
cin >> n;
while(n--){
cin >> m;
for( i = 0 ; i < m ; i++ ) {
cin >> k;
v.push_back(k);
}
unsigned long t_v = 5000*30000;
for ( i = 0 ; i < m ; i++ ) {
unsigned long c = 0;
for ( j = 0; j < m; j++) {
c += abs (v[i] - v[j]);
}
t_v = min(t_v,c);
}
cout  << t_v  << endl;
v.clear();
}
return 0;
}