poj_2000

/*
//ACM Poj 2000
//File: 2000.cpp
//Author: Kangzj
//Mail: Kangzj@mail.bnu.edu.cn
//Date: April 24, 2009
*/
#include
#include
#include


using namespace std;  

int main()
{
  int day;
  int coinDay, coinAll;
  ostringstream buff;  

    while(1)
  {
        cin>>day;
        if(day==0)break;
    float temp=sqrt(1+8*day);
    int tmp=(int)temp;  

    if(temp!=(float)tmp && tmp%2!=0)
    {
      tmp+=2;
    }else if(temp!=(float)tmp && tmp%2==0)
    {
      tmp++;
    }else
    {
      tmp=tmp;
    }
    coinDay=(-1+tmp)/2;
    coinDay--;
    coinAll=coinDay*(coinDay+1)*(2*coinDay+1)/6;  

    coinAll+=(coinDay+1)*(day-(coinDay+1)*coinDay/2);  

    buff< 

需要选择G++才能通过,如果想用C++,只要加几个强制转换就可以了。

Tags: ,
| Posted in 编程算法 | No Comments »

zoj_1002(Fire Net)的一个简单的解法

做了一天,把此题AC了,看到网上用的算法很复杂,发个自己的出来。

思路:
1.如果城市全空,可以不管顺序,随便从哪里开始放“碉堡”,把“碉堡”射程里的城市标记下,后面的“碉堡”不放在这里即可得到结果。
2.但是如果城市中有“墙”的话,就不可以按照1的方法了,因为放置数量的多少与顺序是有关的,所以,怎样来确定这个顺序是很重要的。观察发现,城市里的空地按照领域中的“墙”的数量可以分为五种,即从0到4。再观察,可以得到这样一个结论:按邻域中墙的数目由多到少,往空地上安放“碉堡”,可以使数目最大!
于是按照这个结论,编程如下:

Read the rest of this entry »

Tags: ,
| Posted in 编程算法 | 2 Comments »

poj_1006

Problem: http://poj.grids.cn/problem?id=1006

Solution:
 

#include
#include
#include  

using namespace std;  

int main()
{
    int p, e, i, n=0;
    long cp, ce, ci;
    short d;  

    int j=1;//计数用   

    ostringstream buf;  

    while(1)
    {
        cin>>p>>e>>i>>d;
        if(p==-1 && e==-1 && i==-1 && d==-1)
        {
            break;
        }  

        n=d;
        while(1)
        {
            n++;
            if((n-p)%23==0 && (n-e)%28==0 && (n-i)%33==0)
            {
                n-=d;
                if(n==0)
                {
                    n=d;
                    continue;
                }
                break;
            }
            //cout< <"*";
        }
        buf<<"Case "<

Tags: ,
| Posted in 编程算法 | No Comments »

poj_1004

#include  

using namespace std;  

int main()
{
    int i;
    float all=0, temp=0;  

    for(i=0;i<12;i++)
    {
        cin>>temp;
        all+=temp;
    }  

    all+=0.005;  

    cout.precision(2);  

    //cout.setf(ios_base::showpoint);
    cout< <"$"<

Tags: ,
| Posted in 编程算法 | No Comments »