| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1211 人关注过本帖
标题:ACM(杭电)
只看楼主 加入收藏
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
结帖率:100%
收藏
 问题点数:0 回复次数:11 
ACM(杭电)
实在无聊时自己写着玩的..望大牛们勿喷,给小弟自己打发下时间!
程序代码:
A + B Problem1000 (已AC)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 305423    Accepted Submission(s): 88257
Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
Author
HDOJ

分析:
没什么分析的,EOF文件结束符,其值通常为-1
实现:
#include <stdio.h>

int main()
{
    int a, b;
    while(scanf("%d%d", &a, &b) != EOF) printf("%d\n", a + b);
    return 0;
}


 

[ 本帖最后由 价码问题 于 2013-5-17 08:49 编辑 ]
搜索更多相关主题的帖子: contain Java 
2013-05-01 19:36
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Sum Problem1001 (已AC)
Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 211783    Accepted Submission(s): 51396
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1
5050
Author
DOOM III
分析:
求前n项的和,套用公式,两数相乘注意溢出

实现
#include <stdio.h>

int main()
{
    int n;
    while(scanf("%d", &n) != EOF) printf("%d\n\n", n % 2 ? ((n + 1) >> 1) * n : (n  >> 1) * (n + 1));
    return 0;
}




[ 本帖最后由 价码问题 于 2013-5-17 08:54 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-02 00:49
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
A + B Problem II1002 (已AC)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 155888    Accepted Submission(s): 29496
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
Author
Ignatius.L
分析:
典型大数

实现:
#include <stdio.h>
#include <string.h>

int main()
{
    int T, a[1001], b[1001], len1, len2, len, i, t;
    char s1[1001], s2[1001];
    scanf("%d", &T);
    for(t = 1; memset(a, 0, sizeof(a)), memset(b, 0, sizeof(b)), t <= T; t++)
    {
        scanf("%s%s", s1, s2);
        len1 = strlen(s1); len2 = strlen(s2);
        for(i = 0; i < len1; a[i] = s1[len1 - i++ - 1] - '0') ;
        for(i = 0; i < len2; b[i] = s2[len2 - i++ - 1] - '0') ;
        len = len1 > len2 ? len1 : len2;
        for(i = 0; i < len; i++)
            if((a[i] += b[i]) >= 10) {a[i] %= 10; a[i+1]++;}
        printf("Case %d:\n%s + %s = ", t, s1, s2);
        if(a[len]) printf("%d", a[len]);
        for(i = len - 1; i >= 0; printf("%d", a[i--])) ; printf("\n");
        if(t < T) printf("\n");
    }
    return 0;
}
回复9楼...我的代码没问题,你提交的时候应该是你选的编译器选错了,我选的C编译器.

[ 本帖最后由 价码问题 于 2013-5-4 16:13 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-02 02:32
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Max Sum1003 (已AC)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 104954    Accepted Submission(s): 24156
Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
Sample Output
Case 1:
14 1 4
Case 2:
7 1 6
Author
Ignatius.L
分析:DP中的动态规划(最大字段和),这里没有必要采用函数调用的方法,因为要确定最大和的位置,函数调用只会增加程序的操作数
另外注意这里的sum不能取0,因为all the integers are between -1000 and 1000

实现:
#include <stdio.h>

int main()
{
    int n, t, m, sum, a[100001], b, c, i, j, k;
    scanf("%d", &n);
    for(t = 1; t <= n; t++)
    {
        scanf("%d", &m);
        for(i = 1, sum = -1001, b = 0; i <= m; i++)
        {
            scanf("%d", &a[i]);
            if(b > 0) b += a[i];
            else b = a[i];
            if(b > sum) {sum = b; j = i; c = 0;}
        }
        for(i = j; i >= 1; i--)
        {
            c += a[i];
            if(c == sum) k = i;
        }
        printf("Case %d:\n%d %d %d\n", t, sum, k, j);
        if(t < n) puts("");
    }
    return 0;
}



[ 本帖最后由 价码问题 于 2013-5-4 16:13 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-02 12:57
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Let the Balloon Rise1004 (已AC)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 54466    Accepted Submission(s): 19709
Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contestis over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) --the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output
red
pink
Author
WU, Jiazhi
分析:求出现次数最多的相同的字符串

实现:
#include <stdio.h>
#include <string.h>

int main()
{
    int n, i, j, count[1001] = {0}, max;
    char s[1001][16];
    while(scanf("%d", &n) != EOF && n > 0)
    {
        max = -1;
        for(i = 0; i < n; scanf("%s", s[i++])) ;
        for(i = 0; i < n; i++)
        {
            for(j = 0; j < n; j++)
                if(strcmp(s[i], s[j]) == 0) count[i]++;
            if(count[i] > max) max = count[i];
        }
        for(i = 0; i < n; i++)
            if(count[i] == max)
            {
                printf("%s\n", s[i]);
                break;
            }
        memset(count, 0, sizeof(count));
    }
    return 0;
}



[ 本帖最后由 价码问题 于 2013-5-4 16:13 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-02 22:03
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
呵呵,继续下去!如果你能按顺序解到20题我给你置顶加精。

重剑无锋,大巧不工
2013-05-03 08:32
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Number Sequence1005 (已AC)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 78388    Accepted Submission(s): 18283
Problem Description
A number sequence is defined as follows:
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n).
Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.
Output
For each test case, print the value of f(n) on a single line.
Sample Input
1 1 3
1 2 10
0 0 0
Sample Output
2
5
Author
CHEN, Shunbao
分析:算是一道数学+找规律的题吧,采取打表的方式可以发现每48一循环

实现:
#include <stdio.h>

int main()
{
    int f[1001], i, a, b, c;
    f[1] = f[2] = 1;
    while(scanf("%d%d%d", &a, &b, &c) != EOF)
    {
        for(i = 3; i <= 48; i++) f[i] = (a * f[i - 1] + b * f[i - 2]) % 7;
        if(a == 0 && b == 0 && c == 0) break;
        printf("%d\n", c < 49 ? f[c] : f[c % 48]);
    }
    return 0;
}



[ 本帖最后由 价码问题 于 2013-5-4 16:13 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-03 11:46
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Tick and Tick1006 (未AC)
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6890    Accepted Submission(s): 1900
Problem Description
The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest. You are to calculate how much time in a day that all the hands are happy.
Input
The input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1.
Output
For each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places.
Sample Input
0
120
90
-1
Sample Output
100.000
0.000
6.251
Author
PAN, Minghao
Source
ZJCPC2004
分析:好像是一神题 ,做出来始终与答案有偏差..
实现:下次再看看...最近蛮忙了!先停一下!,代码先贴着,下次修改
#include <stdio.h>
#include <math.h>

int main()

 {
     int i, count;
     double n, sum, a, b, c, t;
     while(scanf("%lf", &n) != EOF && n >= 0)
     {
         count = 0;
         for(i = 1; i <= 43200; i++)
         {
             a = i >= 60 ? (i % 60) * 6.0 : i * 6.0;
             b = i >= 3600 ? (i % 3600) / 10.0 : i / 10.0;
             c = (c == 43200) ? 0 : i / 120.0;
             if(fabs(a-b) >= n && fabs(a-b) <= 360.0-n && fabs(a-c) >= n && fabs(a-c) <= 360.0-n && fabs(b-c) >= n&& fabs(b-c) <= 360-n) count++;
         }
         sum = (n > 0 && n < 120) ? (count - 1.5) / 432.0 : count / 432.0; //先凑合改成和答案一致
        // sum =  count / 432.0;
         printf("%.3lf\n", sum);
     }
     return 0;

 }





[ 本帖最后由 价码问题 于 2013-5-4 16:18 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-04 12:50
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
测试了一下你的代码,其中1002题WA,请确认一下。

重剑无锋,大巧不工
2013-05-04 13:02
价码问题
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-5-1
收藏
得分:0 
程序代码:
Quoit Design1007
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20947    Accepted Submission(s): 5378
Problem Description
Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.
Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
Input
The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.
Output
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.
Sample Input
2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
Sample Output
0.71
0.00
0.75
分析:好像是一道最接近点对问题(其实是英文太差了)
实现:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define fabs(x) (x<0?(-x):x)
#define zero(x) (fabs(x)<1e-6)
typedef struct
{double x;

 double y;

 int index;
}Point;
Point p[100000],q[100000],temp[100000];
int compx(void const *a,void const *b)
{
    double t=((Point *)a)->x-((Point *)b)->x;
    if(t>0) return 1;
    else if(zero(t)) return 0;
    else return -1;
}
int compy(void const *a,void const *b)
{
    double t=((Point *)a)->y-((Point *)b)->y;
    if(t>0) return 1;
    else if(zero(t)) return 0;
    else return -1;
}
double dis(Point a,Point b)
{
    return hypot(a.x-b.x,a.y-b.y);
}
void Merge(Point a[],int m,Point b[],int n,Point r[])//按y轴顺序合并
{
    int i=0,j=0,k=0;
    while(i<m&&j<n)
    {
        if(a[i].y<b[j].y) r[k++]=a[i++];
        else r[k++]=b[j++];
    }
    while(i<m)
        r[k++]=a[i++];
    while(j<n)
        r[k++]=b[j++];
}
double solve(int left,int right,int n,Point p[],Point q[])
{
    int mid;
    double min,t,d1,d2,midx;
    if(n==2) return dis(p[left],p[right]);
    else if(n==3)
    {
        min=dis(p[left],p[right]);
        if((t=dis(p[left],p[left+1]))<min) min=t;
        if((t=dis(p[left+1],p[right]))<min) min=t;
        return min;
    }
    else
    {
        mid=(left+right)/2;
        int i,j,m=left,n=mid+1;       
        for(i=left;i<=right;i++)
            if(p[i].index==mid)
            {q[m++]=p[i];midx=p[i].x;}
            else if(p[i].index<mid)
                q[m++]=p[i];
            else
                q[n++]=p[i];
        d1=solve(left,mid,mid-left+1,q,p);
        d2=solve(mid+1,right,right-mid,q,p);
        min=d1<d2?d1:d2;
        Merge(q+left,mid-left+1,q+mid+1,right-mid,p+left);//把q重新合并为p
        int k=0;
        for(i=left;i<=right;i++)
            if(fabs(p[i].x-midx)<min)
                temp[k++]=p[i];
        for(i=0;i<k-1;i++)
            for(j=i+1;j<k&&temp[j].y-temp[i].y<min;j++)
                if((t=dis(temp[j],temp[i]))<min) min=t;
        return min;
    }
}       
int main()
{
    int i,n;
    double ans;
    while(scanf("%d",&n)&&n!=0)
    {
        for(i=0;i<n;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        qsort(p,n,sizeof(Point),compx);
        for(i=0;i<n;i++)
            p[i].index=i;
        qsort(p,n,sizeof(Point),compy);
        ans=solve(0,n-1,n,p,q);
        printf("%.2lf\n",ans/2);   
    }
    return 0;
}


[ 本帖最后由 价码问题 于 2013-5-7 13:17 编辑 ]

为提问而来....望大家耐心帮助!
2013-05-07 01:54
快速回复:ACM(杭电)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024059 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved