2013 ACM/ICPC Asia Regional Online —— Warmup2 兩個水題

果7發表於2013-09-11

A Computer Graphics Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 150    Accepted Submission(s): 128


Problem Description
In this problem we talk about the study of Computer Graphics. Of course, this is very, very hard.
We have designed a new mobile phone, your task is to write a interface to display battery powers.
Here we use '.' as empty grids.
When the battery is empty, the interface will look like this:
*------------*
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
|............|
*------------*

When the battery is 60% full, the interface will look like this:
*------------*
|............|
|............|
|............|
|............|
|------------|
|------------|
|------------|
|------------|
|------------|
|------------|
*------------*

Each line there are 14 characters.
Given the battery power the mobile phone left, say x%, your task is to output the corresponding interface. Here x will always be a multiple of 10, and never exceeds 100.
 

Input
The first line has a number T (T < 10) , indicating the number of test cases.
For each test case there is a single line with a number x. (0 < x < 100, x is a multiple of 10)
 

Output
For test case X, output "Case #X:" at the first line. Then output the corresponding interface.
See sample output for more details.
 

Sample Input
2 0 60
 

Sample Output
Case #1: *------------* |............| |............| |............| |............| |............| |............| |............| |............| |............| |............| *------------* Case #2: *------------* |............| |............| |............| |............| |------------| |------------| |------------| |------------| |------------| |------------| *------------*
 

Source
 


直接看樣例,有點像電量顯示的東西,直接輸出。
         題目地址:A Computer Graphics Problem
AC程式碼:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;

void show(int p)
{
    int i;
    cout<<"*------------*"<<endl;
    p=10-p;
    for(i=0;i<p;i++)
        cout<<"|............|"<<endl;
    p=10-p;
    for(i=0;i<p;i++)
        cout<<"|------------|"<<endl;
    cout<<"*------------*"<<endl;
}

int main()
{
    int tes,p;
    scanf("%d",&tes);
    int cas=0;
    while(tes--)
    {
        scanf("%d",&p);
        p/=10;
        printf("Case #%d:\n",++cas);
        show(p);
    }
    return 0;
}

//0MS 272K


The Number Off of FFF

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 289    Accepted Submission(s): 136


Problem Description
X soldiers from the famous "*FFF* army" is standing in a line, from left to right.
You, as the captain of *FFF*, decides to have a "number off", that is, each soldier, from left to right, calls out a number. The first soldier should call "One", each other soldier should call the number next to the number called out by the soldier on his left side. If every soldier has done it right, they will call out the numbers from 1 to X, one by one, from left to right.
Now we have a continuous part from the original line. There are N soldiers in the part. So in another word, we have the soldiers whose id are between A and A+N-1 (1 <= A <= A+N-1 <= X). However, we don't know the exactly value of A, but we are sure the soldiers stands continuously in the original line, from left to right.
We are sure among those N soldiers, exactly one soldier has made a mistake. Your task is to find that soldier.
 

Input
The rst line has a number T (T <= 10) , indicating the number of test cases.
For each test case there are two lines. First line has the number N, and the second line has N numbers, as described above. (3 <= N <= 105)
It guaranteed that there is exactly one soldier who has made the mistake.
 

Output
For test case X, output in the form of "Case #X: L", L here means the position of soldier among the N soldiers counted from left to right based on 1.
 

Sample Input
2 3 1 2 4 3 1001 1002 1004
 

Sample Output
Case #1: 3 Case #2: 3
 

Source
 

題目大意:給你一序列的數,他們是按順序報數的,其中有且僅有一個出現了錯誤。問你是第幾號出錯了。

解題思路:解決辦法就是用a[i]-i看差值,我想的是肯定全部都一樣,有一個除外,那個不一樣的就是出錯的,但是WA了,最後吉吉提醒可能有1 2 3這樣的情況。這樣誰錯了?毫無疑問,這樣的話,只能是1出錯了。

題目地址:The Number Off of FFF

AC程式碼:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000005];

int main()
{
    int tes,n,i,p;
    scanf("%d",&tes);
    int cas=0;
    while(tes--)
    {
        scanf("%d",&n);
        for(i=1; i<=n; i++)
            scanf("%d",&a[i]);
        for(i=1; i<=n; i++)
        {
            a[i]=a[i]-i;
        }

        int flag=0;
        for(i=1; i<n; i++)
            if(a[i]!=a[i+1])
            {
                flag=1;
                break;
            }
        if(!flag)  //沒有一個出錯,全部差值都一樣,一號錯
            p=1;
        else
        {
            if(a[1]!=a[2]&&a[1]!=a[3])  //a[1]不同
                p=1;
            if(a[2]!=a[1]&&a[2]!=a[3])  //a[2]不同
                p=2;
            for(i=3; i<=n; i++)
                if(a[i]!=a[i-1]&&a[i]!=a[i-2]) //a[i]不同
                {
                    p=i;
                    break;
                }
        }
        printf("Case #%d: %d\n",++cas,p);
    }
    return 0;
}

/*
23
3
1 2 4
3
1001 1002 1004
3
1 3 4
3
1 5 6
3
2 3 3
3
1 2 3
*/
//78MS 632K


相關文章