HDU 1000,1001,1002,2000,2001,1003,1004,1005,1006

//1000 A + B Problem
//1001 Sum Problem
//1002 A + B Problem II
//2000 ASCII码排序
//2001 计算两点间的距离
//C++中精度控制
//1003 Max Sum
//1004 Let the Balloon Rise
//1005 Number Sequence
//1006 Tick and Tick
//

//


//1006 Tick and Tick//BUG版本
#include <iostream>
#include <algorithm>
#include<iomanip>
using namespace std;
int main()
{
double D = 0;
while(cin>>D,D!=-1)
{
   double d = D/360.0;
   int count = 0;
   int hour = 0 , minute = 0 , second = 0;
   double h = 0,m = 0,s = 0;
   double a,b,c;
   int i = 0;
   for(i=0; i<3600; ++i)
   {
    s = second/60.0 ;
    m = minute/60.0 + s / 60.0 ;
    h = h/60.0 + m/60.0;
    second++;
    if(second == 60)
    {
     second = 0;
     minute++;
     if(minute == 60)
     {
      minute = 0;
      hour++;
     }
    }

    a = s ;
    b = m ;
    c = h ;
    if(a > b)
     swap(a,b);
    if(b > c)
     swap(b,c);
    if(a > b)
     swap(a,b);

    double d1 = b - a;
    double d2 = c - b;
    double d3 = 1 - (d1 + d2);

    if(i%100 == 0)
     cout<<fixed<<setprecision(4)<<d<<" "<<d1<<" "<<d2<<" "<<d3<<" "<<count<<" "<<a<<" "<<b<<" "<<c<<endl;
   
    if(d1 >= d && d2 >= d && d3 >= d)
     count++;

   
    //if(i%30 == 0)
    //{
    // cout<<a<<" "<<b<<" "<<c<<" "<<endl;
    // cout<<h*360<<" "<<m*360<<" "<<s*360<<endl;
    // cout<<hour<<" "<<minute<<" "<<second<<endl<<endl;
    //}
   }
   cout<<count<<endl;
   double result = count/3600.0 * 100;
   cout<<fixed<<setprecision(10)<<result<<endl;
}
return 0;
}


/*
//网上正确的算法
#include<stdio.h>
#include<stdlib.h>
#include<string>
double num[14];
int hash[13];
int cmp(const void *a,const void *b)
{
    return *(double *)a > *(double *)b ? 1 : -1;
}
void hh(double a ,double b)
{
    int i;
    double start,end;
    start = 0;
    end = a;
    for(i=0;i<13;i++)
        if(start <= num[i] && num[i+1] <= end)
            hash[i] ++;
    start = b;
    end = 60;
    for(i=0;i<13;i++)
        if(start <= num[i] && num[i+1] <= end)
            hash[i] ++;
}
void hhh(double a,double b)
{
    int i;
    if(b<0 || a>60)
        return ;
    for(i=0;i<13;i++)
        if(a <= num[i] && num[i+1] <= b)
            hash[i] ++;
}
double happytime(double ms,double hs,double a)
{
    //a <= | 6*t-(t+ms)/10 | <= 360-a
   
    //a <= | 6*t-(t+hs)/120 | <= 360-a
   
    //a <= | (t+ms)/10-(t+hs)/120 | <= 360-a
   
    //计算同时满足上边三个条件的t
    double aa,ab,ac,ad,ba,bb,bc,bd,ca,cb,cc,cd,sum;
   
    aa = (ms-a*10)/59;
    ab = (ms+a*10)/59;
    ac = (ms+10*a-3600)/59;
    ad = (ms+3600-10*a)/59;

    ba = (hs-12*ms-a*120)/11;
    bb = (hs-12*ms+a*120)/11;
    bc = (hs-12*ms+120*a-43200)/11;
    bd = (hs-12*ms+43200-120*a)/11;

    ca = (hs-a*120)/719;
    cb = (hs+a*120)/719;
    cc = (hs+120*a-43200)/719;
    cd = (hs+43200-120*a)/719;

    num[0] = 0;
    num[1] = 60;
    num[2] = aa;
    num[3] = ab;
    num[4] = ac;
    num[5] = ad;
    num[6] = ba;
    num[7] = bb;
    num[8] = bc;
    num[9] = bd;
    num[10] = ca;
    num[11] = cb;
    num[12] = cc;
    num[13] = cd;

    qsort(num,14,sizeof(num[0]),cmp);
    memset(hash,0,sizeof(hash));
    sum = 0;
    hh(aa,ab);
    hh(ba,bb);
    hh(ca,cb);
    hhh(ac,ad);
    hhh(bc,bd);
    hhh(cc,cd);
    for(int i=0;i<13;i++)
        if(hash[i]>=6)
            sum += num[i+1] - num[i];
    return sum;
}
int main()
{
    int i,start;
    double ans,a;
    while(scanf("%lf",&a),a!=-1)
    {
        ans = 0;
        start = 0;
        for(i=0;i<720;i++)
        {
            if(i==109)
                i = i;
            ans += happytime(start%3600,start,a);
            start += 60;
        }
        printf("%.3lf\n",ans*100/43200);
    }
    return 0;
}
*/

/*


// 分析:
//1,题中(1 <= A, B <= 1000, 1 <= n <= 100,000,000),可知用蛮力肯定行不通。
//2, (A * f(n - 1) + B * f(n - 2)) mod 7 =(A%7*f(n-1)+B%7*f(n-2))%7
//3,因f(i)和f(i+1) 只有49种组合,因为(f(i),(i+1)均只有7种选择,就是只能是0,1,2,3,4,5,6中的一个。故周期<=49。

//解题:
//1,先求周期,顺便把第一个周期的f(n)求出来。
//2,利用周期,直接求其余f(n)。


//1005 Number Sequence
#include <iostream>
using namespace std;
int main()
{
int a = 0,b = 0;
int num;
int result[100] = {0};
cin>>a>>b>>num;
while(a!=0 || b!=0 || num!=0)
{
   memset(result,0,100);
   result[1] = 1;
   result[2] = 1;
   int i = 3;
   int loop = 0;
   a = a % 7;
   b = b % 7;
   for( ; i<=99; ++i)
   {
    result[i] = (a * result[i-1] + b * result[i-2])%7;
    //cout<<i<<"   "<<result[i]<<endl;
    if(result[i] == result[5]&&result[i-1] == result[4]&&result[i-2] == result[3]&& i > 5)
     break;
   }
   loop = i - 5;
   //WA的
   //cout<<"loop="<<loop<<endl;
   //int temp = num % loop;
   //cout<<"temp="<<temp<<endl;
   //if(temp == 0) temp = loop;
   //cout<<result[temp]<<endl;
   //AC的
   if(num<5) cout<<result[num]<<endl;
   else cout<<result[(num-5) % loop + 5]<<endl;
   cin>>a>>b>>num;
}
return 0;
}
*/

/*
#include <iostream>
using namespace std;

#define M 52

int main()
{
    int f[10000];
    int a,b,n;
    while(cin>>a>>b>>n&&(a||b||n) )
    {
        f[1]=1;
        f[2]=1;
        a=a%7;
        b=b%7;
        for(int i=3;i<=M;i++)
        {
            f[i]=(a*f[i-1]+b*f[i-2]) % 7;
            if(f[i-1]==f[3]&&f[i]==f[4]&&i>4) break;

        }
        int t=i-4;
        if(n<4) cout<<f[n]<<endl;
        else cout<<f[(n-4)%t+4]<<endl;
    }
     
    return 0;
}
*/

/*
//Time Limit Exceeded
#include <iostream>
using namespace std;
int main()
{
    int a = 0,b = 0;
    int num;
    int result[4] = {0};
   
    cin>>a>>b>>num;
    while(a!=0 && b!=0 && num!=0)
    {
        result[1] = 1;
        result[2] = 1;
        int i = 3;
        for( ; i<=num; ++i)
        {
            result[3] = (a * result[2] + b * result[1])%7;
            result[1] = result[2];
            result[2] = result[3];
        }
   if(num<=2)
    cout<<"1"<<endl;
   else
    cout<<result[3]<<endl;
        cin>>a>>b>>num;
    }
    return 0;
}
*/
/*
//1004 Let the Balloon Rise
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string s[1000];
int num[1000] = {0};
while(cin>>n,n!=0)
{
   memset(num,0,1000);
   int iMax = 0;
   int iNum = 0;
   int i = 0;
   for( ; i<n; ++i)
   {
    cin>>s[i];
    int j = 0;
    for( ; j<=i; ++j)
    {
     if(s[j] == s[i])
      ++num[i];
    }
    if(iMax < num[i])
    {
     iMax = num[i];
     iNum = i;
    }
   
   }
   cout<<s[iNum]<<endl;
}
return 0;
}
*/

/*460B
#include <iostream>
using namespace std;int main(){int n;cin>>n;int times = 0;while(n--){++times;int nums = 0;cin>>nums;int posB = 1,posE = 1;int now = 0;int max = 0;int times1 = 0;int tempB = 1;while(nums--){++times1;int temp;cin>>temp;if(now+temp < temp){tempB = times;now = temp;}else{now += temp;}if(now > max){posB = tempB;posE = times1;max = now;}}cout<<"Case "<<times<<":"<<endl;cout<<max<<" "<<posB<<" "<<posE<<endl;if(n!=0)cout<<endl; }return 0;}
*/
/*
//1003 Max Sum 673B
//1.首先,读取第一个数据,令now和max等于第一个数据,初始化pos1,pos2,x位置
//2.然后,读入第二个数据,判断
//①. 若是now+temp<temp,表示当前读入的数据比之前存储的加上当前的还大,说明可以在当前另外开始记录,更新now=temp
//②. 反之,则表示之前的数据和在增大,更新now=now+temp
//3.之后,把now跟max做比较,更新或者不更新max的值,记录起始、末了位置
//4.循环2~3步骤,直至读取数据完毕。
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int times = 0;
while(n--)
{
   ++times;
   int nums = 0;
   int temp;
   cin>>nums>>temp;
   int posB = 1,posE = 1;
   int now = temp;
   int max = temp;
   int times1 = 1;
   --nums;
   int tempB = 1;
   while(nums--)
   {
    ++times1;
   
    cin>>temp;
    if(now+temp < temp)
    {
     tempB = times1;
     now = temp;
    }
    else
    {
     now += temp;
    }
    if(now > max)
    {
     posB = tempB;
     posE = times1;
     max = now;
    }
   }
   cout<<"Case "<<times<<":"<<endl;
   cout<<max<<" "<<posB<<" "<<posE<<endl;
   if(n!=0)
    cout<<endl;  
}

return 0;
}
/*


/*
//C++中精度控制
#include <iostream>
#include<iomanip>//格式控制函数声明
using namespace std;
int main()
{
double n1=0.123456789,n2=0.123;
cout<<fixed<<setprecision(6)<<n1<<endl;//精确到小数点后6位 //一定要这样写,不然没效果
cout<<fixed<<setprecision(6)<<n2<<endl;//精确到小数点后6位
cout<<fixed<<setprecision(9)<<n1<<endl;//精确到小数点后9位
cout<<fixed<<setprecision(9)<<n2<<endl;//精确到小数点后9位
return 0;
}
*/

/*
//2001 计算两点间的距离
//使用勾股定理

#include <stdio.h>
#include <math.h>
int main()
{
double x1 = 0,y1 = 0,x2 = 0,y2 = 0;

while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
{
   double x = x1 - x2;
   double y = y1 - y2;
   double result = sqrt(x*x + y*y);
   printf("%.2lf\n",result);
}
return 0;
}
*/

/*
//2000 ASCII码排序
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
   if(s[0]>=s[1]) swap(s[0],s[1]);
   if(s[1]>=s[2]) swap(s[1],s[2]);
   if(s[0]>=s[1]) swap(s[0],s[1]);
   cout<<s[0]<<" "<<s[1]<<" "<<s[2]<<endl;

}
return 0;
}
/*

/*
//1002 A + B Problem II
//大数求和,主要思想:使用字符串存储大数,从2位数最低位开始相加,
//并注意如果>=10就要产生进位,注意的地方:2个数位数不同而带来的错位
//和最后结果可能比最大数位数大的情况(如 :99 + 2 = 101 )

#include <iostream>
#include <string>
using namespace std;

int main()
{
int n = 0,times = 1;
string s1,s2,result;
cin>>n;
while(n--)
{
   cin>>s1>>s2;
   int l1 = s1.length();
   int l2 = s2.length();
   int nR = 0;
   while(l1 >0 || l2 >0)
   {
    int n1,n2;
    if(l1!=0)
     n1 = (char)s1[--l1] - 48;
    else
     n1 = 0;
    if(l2!=0)
     n2 = (char)s2[--l2] - 48;
    else
     n2 = 0;
    nR = nR + n1 + n2;
    if(nR>=10)
    {
     int iTemp = nR - 10;
     nR = 1;
     char c = 48 + iTemp;
     result = c + result;
    }
    else
    {
     char c = 48 + nR;
     nR = 0;
     result = c + result;
    }
   }
   if(nR) result = '1' +result;

   cout<<"Case "<<times++<<":"<<endl;
   cout<<s1<<" + "<<s2<<" = "<<result<<endl;
   if(n!=0)
    cout<<endl;
   
   result = "";
   s1 = "";
   s1 = "";
}
return 0;
}
*/

/*
//1001 Sum Problem
#include <stdio.h>
int main()
{
int num = 0;
int i = 0,result = 0;

while(scanf("%d",&num)!=EOF)
{
   for(i=1; i<=num; ++i)
    result +=i;
   printf("%d\n\n",result);
   result = 0;
}
return 0;
}
*/

//1000 A + B Problem
/*
#include <iostream>
using namespace std;

int main()
{
int a,b;
while(cin>>a>>b)
{
   cout<<a+b<<endl;
}
return 0;
}
*/
/*
#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
   printf("%d\n",a+b);
}
return 0;
}
*/

作者:BuildNewApp
出处:http://syxchina.cnblogs.comBuildNewApp.com
本文版权归作者、博客园和百度空间共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则作者会诅咒你的。
如果您阅读了我的文章并觉得有价值请点击此处,谢谢您的肯定1。
原文地址:https://www.cnblogs.com/syxchina/p/2197387.html