Monthly Archives: January 2017

472B : Design Tutorial: Learn from Life

  #Solutions #include <bits/stdc++.h> using namespace std; int main() { int b,c,tmp,n,k; int sum=0; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(int i=n-1;i>=0;i-=k) { sum+=(a[i]-1)*2;     //1st floor to n-1 floor } cout<<sum<<endl; }

Rate this:

Posted in Uncategorized | Leave a comment

1260: Sales

Problem Link #Solution #include <bits/stdc++.h> using namespace std; int main() { int n,m,t; cin>>t; while(t–){ cin>>n; vector<int>a,b; vector<double>nw; for(int i=0;i<n;i++) {int x; cin>>x; a.push_back(x); } int m=a.size(); int co=0; for(int i=0;i<m;i++) { for(int j=i+1;j<m;j++) { if(a[i]<=a[j]) co++; } } cout<<co<<endl; … Continue reading

Rate this:

Posted in Uncategorized | Tagged , | Leave a comment

11565:Simple Equations

Problem Link #Solution #include<stdio.h> #include<stdbool.h> bool eqn(int a,int b,int c) { int i,j,k; for(i=-100;i<=100;i++) for(j=-100;j<=100;j++) for(k=-100;k<=100;k++) { if(i!=j&&j!=k&&i!=k&&(i+j+k==a)&&(i*j*k==b)&&(i*i+j*j+k*k==c)) {printf(“%d %d %d\n”,i,j,k); return true;} } return false; } int main() { int a,b,c,t,flag=1; scanf(“%d”,&t); while(t–) {scanf(“%d %d %d”,&a,&b,&c); if(!eqn(a,b,c)) printf(“No solution.\n”);} … Continue reading

Rate this:

Posted in Uncategorized, uva | Tagged | Leave a comment

1237:Expert Enough?

  Problem Link #Solution #include <bits/stdc++.h> using namespace std; int main() { int t; int n,m; cin>>t; while(t–) { cin>>n; string s[n]; int lw[n],hi[n]; for(int i=0;i<n;i++) {cin>>s[i]>>lw[i]>>hi[i]; } cin>>m;int pos; for(int i=0;i<m;i++) {int x; int flag=0; cin>>x; for(int i=0;i<n;i++) { … Continue reading

Rate this:

Posted in Uncategorized | Leave a comment

Converting string of numbers to individual numbers

  #include <bits/stdc++.h> using namespace std; int main() { string st; getline(cin,st); stringstream num; num<<st; string t; vector<int>v; int x; while(getline(num,t,’ ‘)) { if(stringstream(t)>>x) { v.push_back(x); } } for(int i=0;i<v.size();i++) { cout<<v[i]<<endl; } // your code goes here return 0; … Continue reading

Rate this:

Posted in Uncategorized | Tagged , | Leave a comment

484:The Department of Redundancy Department

Problem Link #Solution #include <bits/stdc++.h> using namespace std; map<int,int> f; vector<int>a; int main() { int n; while(scanf(“%d”,&n)!=EOF) { if(!f[n]) {f[n]=1; a.push_back(n); } else f[n]++; } for(int i=0;i<a.size();i++) { cout<<a[i]<<” “<<f[a[i]]<<endl; } return 0; }

Rate this:

Posted in Uncategorized | Leave a comment

3278: Catch That Cow

  Problem Link #Solution #include<bits/stdc++.h> using namespace std; struct point{ int x; int tym; }; int vis[100010]; int n,k; #include<cstdio> int bfs() {memset(vis,0,sizeof vis); point val; val.x=n; val.tym=0; vis[n]=1; queue<point>q; point a,b,c; q.push(val); while(!q.empty()) { point val=q.front(); q.pop(); if(val.x==k) return … Continue reading

Rate this:

Posted in pku, Uncategorized | Tagged , | Leave a comment