Friday, 21 September 2012

UVa 12390 - Distributing Ballot Boxes Solution

#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>

using namespace std;

#define INF (1<<63)-1
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
#define MOD 1000000007
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define KS printf("Case %d: ",kk++)
#define NL printf("\n")
#define MX 5000010


int n,m,arr[MX];

bool chk(int md)
{
 int tmp, mm=m;
 for (int i = 0; i < n; i++)
 {
  if (arr[i] % md == 0)
   tmp = arr[i] / md;
  else
   tmp = arr[i] / md + 1;
  mm -= tmp;
  if (mm < 0)
   return false;
 }
 return true;
}
int main()
{
    while(scanf("%d%d",&n,&m)==2)
    {
        if (n==-1 && m==-1) break;
        int mx=0;
        for (int i = 0; i < n; i++)
   {
       scanf ("%d", &arr[i]);
       mx=max(mx,arr[i]);
   }

        int lft=0,rgt=mx,mid;
        while(lft<rgt)
        {
            mid=(lft+rgt)/2;
            if(chk(mid))
                rgt=mid;
            else
                lft=mid+1;

        }
        cout<<lft<<endl;
    }
return 0;
}

UVa 12394 - Peer Review Solution

#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>

using namespace std;

#define INF (1<<63)-1
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 1;i<=n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
#define MOD 1000000007
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define KS printf("Case %d: ",kk++)
#define NL printf("\n")
#define MX 1010


int main()
{
    int k,n,tmp,cnt;
    bool chk;
    string institute[MX];
    while(cin>>k>>n)
    {
        if(k==0 && n==0)    break;
        cnt=0;
        vector<int>v[MX];
        set<int>st[MX];
        for(int i=1;i<=n;i++)
        {
            cin>>institute[i];
            for(int j=1;j<=k;j++)
            {
                cin>>tmp;
                v[tmp].PB(i);
                st[tmp].insert(i);
            }
        }

        for(int i=1;i<=n;i++)
        {
            chk=true;
            if(v[i].size()!=st[i].size())   chk=false;
            else if(v[i].size()!=k) chk=false;
            else
            {
                for(int j=0;j<v[i].size();j++)
                    if(institute[i]==institute[v[i][j]])
                    {
                        chk=false;
                        break;
                    }
            }

            if(!chk)    cnt++;
        }

        if(!cnt)    cout<<"NO PROBLEMS FOUND"<<endl;
        else if(cnt==1) cout<<"1 PROBLEM FOUND"<<endl;
        else cout<<cnt<<" PROBLEMS FOUND"<<endl;

    }
return 0;
}

SPOJ 11581. The Famous Clock Solution

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define MX 1000000

using namespace std;

int main()
{
    string temp;
    int c=1;


    while (cin >> temp)
    {
        Case(c++);

        if (temp=="I")
            cout << "1\n";

        if (temp=="II")
            cout << "2\n";

        if (temp=="III")
            cout << "3\n";

        if (temp=="IV")
            cout << "4\n";

        if (temp=="V")
            cout<< "5\n";

        if (temp=="VI")
            cout << "6\n";

        if (temp=="VII")
            cout << "7\n";

        if (temp=="VIII")
            cout << "8\n";

        if (temp=="IX")
            cout << "9\n";

        if (temp=="X")
            cout << "10\n";

        if (temp=="XI")
            cout << "11\n";

        if (temp=="XII")
            cout << "12\n";
    }
    return 0;
}

SPOJ 11573. A Famous ICPC Team Solution

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define MX 1000000

using namespace std;

int main()
{
    LL a[4],c=1;

    while (cin >> a[0])
    {
        for (int i=1;i<4;i++)
            cin >> a[i];

        sort (a,a+4);

        Case(c++);

        cout << a[2]+a[3] << endl;


    }
    return 0;
}

SPOJ 11572. A Famous Music Composer Solution

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define MX 1000000

using namespace std;

int main()
{
    map<string,string>exchange;
    map<string,bool> visit;
    string a,b;
    int c=1;

    exchange["A#"]="Bb";exchange["Bb"]="A#";visit["A#"]=true;visit["Bb"]=true;
    exchange["C#"]="Db";exchange["Db"]="C#";visit["C#"]=true;visit["Db"]=true;
    exchange["D#"]="Eb";exchange["Eb"]="D#";visit["D#"]=true;visit["Eb"]=true;
    exchange["F#"]="Gb";exchange["Gb"]="F#";visit["F#"]=true;visit["Gb"]=true;
    exchange["G#"]="Ab";exchange["Ab"]="G#";visit["G#"]=true;visit["Ab"]=true;

    while (cin >> a >> b)
    {
        Case(c++);

        if (visit[a])
        {
            cout << exchange[a] << ' ';
        }

        else
        {
            cout << "UNIQUE\n";

            continue;
        }

        cout << b << endl;
    }
    return 0;
}

SPOJ 11578. A Famous City Solution

#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>

using namespace std;

#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long



int main()
{
    int n,t,kk=1,histogram[100000+10],i,left[100000+10],right[100000+10],mx;
    stack<int>stk;
    
    while(cin>>n)
    {
        
        map<pair<int,int>,int>mp;

        for(i=1;i<=n;i++)
        {
            scanf("%d",&histogram[i]);
            histogram[i]++;
        }


        while(!stk.empty())
            stk.pop();

        stk.push(0);
        histogram[0]=0;

        for(i=1;i<=n;i++)
        {
            while(histogram[stk.top()]>=histogram[i])
                stk.pop();

             left[i]= stk.top()+1;
             stk.push(i);
        }

        while(!stk.empty())
            stk.pop();

        stk.push(n+1);
        histogram[n+1]=0;


        for(i=n;i>0;i--)
        {
            while(histogram[stk.top()]>=histogram[i])
                stk.pop();

             right[i]=  stk.top()-1;
             stk.push(i);
        }
     
        int cnt=0;
        for(i=1;i<=n;i++)
        {
            if(histogram[i]!=1)
            {

            if(mp[MP(left[i],right[i])]!=1)
            {
                cnt++;
                mp[MP(left[i],right[i])]=1;
            }
            }
        }
        cout<<"Case "<<kk++<<": "<<cnt<<endl;
    }
return 0;
}

UVa 12482 - Short Story Competition Solution

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<iterator>
#include<assert.h>

using namespace std;

#define INF (1<<63)-1
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
#define MOD 1000000007
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define KS printf("Case %d: ",kk++)
#define NL printf("\n")
#define MX 100000



int main()
{
int t,kk=1,n,l,c,sl,tc;
string s;
while(cin>>n)
{
    cin>>l>>c;
    int line=1;
    cin>>s;
    tc=s.size();
    FOR(i,n-1)
    {
        cin>>s;
        if((tc+s.size()+1)<=c)
        {
            tc+=s.size()+1;
        }
        /*else if(tc<c)
        {
            line++;
            tc=s.size();
        }*/
        else
        {
            //cout<<s<<endl;
            line++;
            tc=s.size();
        }
    }
    //cout<<line<<endl;
    int ans=line/l;
    if(line%l)
        ans++;
    cout<<ans<<endl;
}
return 0;
}

UVa 12488 - Start Grid Solution

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<iterator>
#include<assert.h>

using namespace std;

#define INF (1<<63)-1
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
#define MOD 1000000007
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define KS printf("Case %d: ",kk++)
#define NL printf("\n")
#define MX 100000



int main()
{
int t,kk=1,n,l,c,sl,arr[30],arr2[30],move,pos,tmp;
string s;
while(cin>>n)
{
    FOR(i,n)
        cin>>arr[i];
    FOR(i,n)
        cin>>arr2[i];

    move=0;

    FOR(i,n)
    {
       for(int j=i;j<n;j++)
            if(arr2[i]==arr[j])
            {
                pos=j;
                break;
            }
        for(int j=pos;j>i;j--)
        {
            arr[j]=arr[j-1];
            move++;
        }

    }
    cout<<move<<endl;
}
return 0;
}

UVa 12485 - Perfect Choir Solution

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<iterator>
#include<assert.h>

using namespace std;

#define INF (1<<63)-1
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
#define MOD 1000000007
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define KS printf("Case %d: ",kk++)
#define NL printf("\n")
#define MX 100000



int main()
{
int n,arr[MX];
string s;
while(cin>>n)
{
    int sum=0;
    FOR(i,n)
        {
            cin>>arr[i];
            sum+=arr[i];
        }

    if(sum%n)
        cout<<"-1"<<endl;
    else
    {
        sum/=n;
        int cnt=1;
        int pos=0;
        while(arr[pos]<sum)
        {
            cnt+=(sum-arr[pos]);
            pos++;
        }
        cout<<cnt<<endl;
    }


}
return 0;
}

How to open pen drive files when the folder affected by shortcut virus

First, click Start, Run, and type cmd. Command Prompt window will open, and type this attribute:

attrib -h -r -s /s /d g:\*.*
Note: Just replace g: of whatever your flash drive directory letter.

Sunday, 2 September 2012

how to set address bar to search google

Type about:config in address bar of Mozilla Firefox.  You must confirm you know what you're doing.
Type keyword.URL in filter box.
right click on the preference name and hit Modify
paste this into the box that opens:  http://www.google.co.uk/search?btnG=Google+Search&q=
Now Type browser.search.
defaultenginename in filter box
right click on the preference name and hit Modify
paste this into the box that opens: Google