Translate

Views

Thursday, August 1, 2019

Solution Kattis · ICPC Awards

https://open.kattis.com/problems/icpcawards
#include<bits/stdc++.h>
using namespace std;

int n;
string uni, school;
map<string, bool> m;
vector< pair<string, string> > vp;

int main(){
 cin >> n;
 for(int i=1; i<=n; i++){
  cin >> uni >> school;
 
  if (!m[uni]){
   m[uni]=true;
   vp.push_back(make_pair(uni,school));  
  }
 }
 for(int i=0; i<12; i++) 
           cout<<vp[i].first<<" "<<vp[i].second<<"\n";
 
}
Good luck! If you need help please leave a comment :) 

Wednesday, July 31, 2019

Solution Kattis · Supercomputer

https://open.kattis.com/problems/supercomputer
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define N 1000111
#define node vector<int>::iterator 
using namespace std;

int pos,n,q;
int A, B, K;
int a[N];
int st[4*N];

void build(int id, int l, int r){
    if (l==r){
        a[l]=abs(a[l]-1);
        st[id]=a[l];  
        return;
    }
    int mid=(l+r)/2;
    if (pos<=mid) build(id*2, l, mid);
    else build(id*2+1, mid+1, r);
    st[id]= st[id*2] + st[id*2+1];
}

int get(int id, int l, int r){
    if (A > r || B < l) return 0;
    if (l >= A && r<= B) return st[id]; 
    int mid=(l+r)/2;
    return get(id*2, l, mid) + get(id*2+1, mid+1, r);
}

int main(){
    cin >> n >> q; 
    FOR(i, 1, q){
        char cmd;   cin>>cmd;
        if (cmd=='F'){
            cin >> pos;
            build(1,1,n);
        }
        else{
            cin >> A >> B;
            cout << get(1, 1, n) <<"\n";
        }
    }
}
Good luck! If you need help please leave a comment :) 

Tuesday, July 30, 2019

Solution Kattis · Simon Says

https://open.kattis.com/problems/simonsays
#include<bits/stdc++.h>
using namespace std;

int T;
string s,x;

int main(){ 
ios_base::sync_with_stdio(false); 
cin.tie(NULL); cout.tie(NULL);
 
 cin >> T; getline(cin, s);
 while(T--){ x="";
 
  getline(cin, s);
 
  for(int i=0; i<10; i++) x+=s[i];
 
  if (x=="Simon says"){
   s.erase(0, 10);
   cout<<s<<"\n";
  }  
 }
}
Good luck! If you need help please leave a comment :) 

Solution Kattis · The Easiest Problem Is This One

https://open.kattis.com/problems/easiest
#include<bits/stdc++.h>
using namespace std;

int sum(int n){
 int s=0;
 while(n>0){
  s+=n%10;
  n/=10;
 }
 return s;
}

int main(){
 int n;
 while(cin>>n){ if (n==0) break;
  int i=11; 
  while(sum(i*n) != sum(n)){
   i++;  
  }
  cout<<i<<"\n";
 }
}
Good luck! If you need help please leave a comment :) 

Monday, July 29, 2019

Solution Kattis: 10 Kinds of People

https://open.kattis.com/problems/10kindsofpeople
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define N 1001
using namespace std;

int n, m, q, bi, bj, ei, ej, cl;
char a[N][N];
int color[N][N];
int h[4]={1,-1,0,0};
int c[4]={0,0,-1,1};

void flood_fill(int i, int j, int cl){
 FOR(k, 0 ,3){
  int ii=i+h[k];
  int jj=j+c[k];
  
  if (ii>=0 && ii<=n && jj>=0 && jj<=m)
  if (color[ii][jj]==0 && a[ii][jj]==a[i][j]){
   color[ii][jj]=cl;
   flood_fill(ii, jj, cl);
  }
 } 
}

int main(){  
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 cin >> n >> m;
 FOR(i, 1, n) FOR(j, 1, m) cin >> a[i][j];
 
 FOR(i, 1, n) FOR(j, 1, m) 
 if (color[i][j]==0){
  cl++;
  color[i][j]=cl;
  flood_fill(i,j,cl); 
 } 
 
 cin >> q;
 FOR(i, 1, q){
  cin >> bi >> bj >> ei >> ej;
  
  if (color[bi][bj]!=color[ei][ej]) 
                    cout<<"neither\n";
  else 
  if (a[bi][bj]=='1') cout<<"decimal\n"; 
                    else cout<<"binary\n"; 
 }
}
Good luck! If you need help please leave a comment :) 

Solution Kattis: No Duplicates

https://open.kattis.com/problems/nodup
#include<bits/stdc++.h>
using namespace std;

map<string, int> m;
string s;

bool check(){
 for(map<string, int> :: iterator it=m.begin(); it!=m.end(); it++) 
  if (it->second > 1) return false;
 return true;
}

int main(){
 while(cin >> s) m[s]++;
 if (check()) cout<<"yes"; else cout<<"no";
}
Good luck! If you need help please leave a comment :) 

Sunday, July 28, 2019

Solution Kattis: Ptice

https://open.kattis.com/problems/ptice
#include<bits/stdc++.h>
using namespace std;

int n, a, b, c, maX;
string s;
string A="ABC";
string B="BABC";
string C="CCAABB";

int main(){
 while(A.size()<=100) A+=A;
 while(B.size()<=100) B+=B;
 while(C.size()<=100) C+=C;
 
 cin >> n >> s;
 
 for(int i=0; i<n; i++){
  if (s[i]==A[i]) a++;
  if (s[i]==B[i]) b++;
  if (s[i]==C[i]) c++;
  maX= max( max(a,b), c );
 }
 
 cout<<maX<<"\n";
 if (a==maX) cout<<"Adrian\n";
 if (b==maX) cout<<"Bruno\n";
 if (c==maX) cout<<"Goran";
}
Good luck! If you need help please leave a comment :) 

Solution Kattis: Reversed Binary Numbers

https://open.kattis.com/problems/reversebinary
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<=b; i++)
using namespace std;

int n, d, x, ans;
int a[1000111];

void dec_bin_rev(){
 while(n>0){
  a[d]= n%2;
  n= n/2;
  d++;
 }
 d--;
 
}
void bin_dec(){
 x= d;
 FOR(i, 0, d){
  ans+= a[i]*pow(2,x);
  x--;
 }
 cout << ans;
}

int main(){
 cin >> n;
 dec_bin_rev();
 bin_dec();
}
Good luck! If you need help please leave a comment :) 

Solution Kattis: Roaming Romans

https://open.kattis.com/problems/romans
#include<bits/stdc++.h>
using namespace std;

double n;

int main(){
 cin >> n;
 cout <<(int)round(n*5280/4854*1000);
}
Good luck! If you need help please leave a comment :) 

Saturday, July 27, 2019

Solution Kattis: Skener

https://open.kattis.com/problems/skener
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<=b; i++)
using namespace std;

int n, m, mm, nn;
int ii, jj;
char x;
char a[1001][1001];

int main(){
 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 cin >> n >> m >> nn >> mm;
 
 FOR(i, 1, n)
 FOR(j, 1, m){
  cin >> x;
  
  ii= i*nn;
  jj= j*mm;
   FOR(k, ii-nn+1, ii)
   FOR(l, jj-mm+1, jj) a[k][l]= x; 
 }
 
 FOR(i, 1, n*nn){
  FOR(j, 1, m*mm) cout<<a[i][j];
  cout<<"\n"; 
 }
 
}
Good luck! If you need help please leave a comment :) 

Thursday, July 25, 2019

Solution Kattis: Stand on Zanzibar

https://open.kattis.com/problems/zanzibar
#include<bits/stdc++.h>
using namespace std;

int T, n, ans;
vector<int> v;

int main(){ 
 cin >> T;
 while(T--){ ans=0; v.clear();
 
  while(cin>>n){
   if (n==0) break;
   v.push_back(n);
  }
  
  for(int i=1; i<v.size(); i++){
   if (v[i]/v[i-1]<2) continue;
   ans+=v[i]-v[i-1]*2;
  }
  
  cout<<ans<<"\n";
 }
}
Good luck! If you need help please leave a comment :) 

Solution Kattis: Star Arrangements

https://open.kattis.com/problems/stararrangements
#include<bits/stdc++.h>
using namespace std;

int n;

bool check(int i){
 for(int j=n/i; j>=1; j--){
  if (i*j+(i-1)*j==n) return true;
  if (i*j+(i-1)*(j-1)==n) return true;
 }
 return false;
}

int main(){
 cin >> n; cout<<n<<":\n";
 for(int i=2; i<=n-1; i++){
  if (check(i)) cout<<i<<","<<i-1<<"\n";  
  if (n%i==0) cout<<i<<","<<i<<"\n";
 } 
}
Good luck! If you need help please leave a comment :)