2014年4月23日 星期三

[UVA] 10642 - Can You Solve It?

/*20140423 hanting*/
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    for(int times=1;times<=N;times++)
    {
        int x[2],y[2];
        for(int i=0;i<2;i++) cin>>x[i]>>y[i];
        int t1=0,t2=0;
        for(int i=1;i<=x[0]+y[0];i++)
        {
            t1+=i;
        }
        t1+=x[0];
        for(int i=1;i<=x[1]+y[1];i++)
        {
            t2+=i;
        }
        t2+=x[1];
        int ans=t2-t1;
        cout<<"Case "<<times<<": "<<ans<<endl;
    }
    return 0;
}

2014年4月19日 星期六

[UVA] 10908 - Largest Square

/*20140419 hanting*/
#include <iostream>
using namespace std;
int main()
{
    int t,m,n,q;
    cin>>t;
    while(t--)
    {
        cin>>m>>n>>q;
        char ch[102][102]={'\0'};//初始
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                cin>>ch[i][j];
            }
        }
        cout<<m<<" "<<n<<" "<<q<<endl;
        while(q--)
        {
            int r=0,c=0;
            cin>>r>>c;
            char center=ch[r][c];
            int ans=1;
            for(int k=3;k>=0;k+=2)//邊長
            {
                for(int i=0;i<k;i++)//從中心左上角開始跑k*k個字元
                {
                    for(int j=0;j<k;j++)
                    {
                        if(ch[r-((k-1)/2)+i][c-((k-1)/2)+j]!=center)
                        {
                            i=k;
                            ans=k-2;k=-3;
                            break;
                        }
                    }
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

[UVA] 10170 - The Hotel with Infinite Rooms

/*20140419 hanting*/
#include <iostream>
using namespace std;
int main()
{
    long long s,d;
    while(cin>>s>>d)
    {
        long long i;
        long long sum=0;
        for(i=s;sum+i<d;i++)
        {
            sum+=i;
        }
        cout<<i<<endl;
    }
    return 0;
}