2013成都網路賽 兩個簡單題

果7發表於2013-09-14

We Love MOE Girls

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 205    Accepted Submission(s): 154


Problem Description
Chikami Nanako is a girl living in many different parallel worlds. In this problem we talk about one of them.
In this world, Nanako has a special habit. When talking with others, she always ends each sentence with "nanodesu".
There are two situations:
If a sentence ends with "desu", she changes "desu" into "nanodesu", e.g. for "iloveyoudesu", she will say "iloveyounanodesu". Otherwise, she just add "nanodesu" to the end of the original sentence.
Given an original sentence, what will it sound like aften spoken by Nanako?
 

Input
The first line has a number T (T <= 1000) , indicating the number of test cases.
For each test case, the only line contains a string s, which is the original sentence.
The length of sentence s will not exceed 100, and the sentence contains lowercase letters from a to z only.
 

Output
For every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1. Then output which Nanako will say.
 

Sample Input
2 ohayougozaimasu daijyoubudesu
 

Sample Output
Case #1: ohayougozaimasunanodesu Case #2: daijyoubunanodesu
 

Source
 


題目地址:We Love MOE Girls
AC程式碼:
#include<iostream>
#include<cstring>
#include<string>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
char p[105];
char t[5];

int main()
{
    int tes,i;
    int cas=0;
    int len;
    scanf("%d",&tes);
    while(tes--)
    {
        scanf("%s",p);
        len=strlen(p);
        printf("Case #%d: ",++cas);
        if(len<4)
        {
            cout<<p<<"nanodesu"<<endl;
        }
        else
        {
            t[0]=p[len-4];
            t[1]=p[len-3];
            t[2]=p[len-2];
            t[3]=p[len-1];
            t[4]='\0';
            if(strcmp(t,"desu")==0)
            {
                for(i=0;i<len-4;i++)
                    cout<<p[i];
                cout<<"nanodesu"<<endl;
            }
            else
               cout<<p<<"nanodesu"<<endl;
        }
    }
    return 0;
}


A Bit Fun

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 395    Accepted Submission(s): 254


Problem Description
There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)
The problem is really simple: please count the number of different pairs of (i, j) where f(i, j) < m.
 

Input
The first line has a number T (T <= 50) , indicating the number of test cases.
For each test case, first line contains two numbers n and m.(1 <= n <= 100000, 1 <= m <= 230) Then n numbers come in the second line which is the array a, where 1 <= ai <= 230.
 

Output
For every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1.
Then follows the answer.
 

Sample Input
2 3 6 1 3 5 2 4 5 4
 

Sample Output
Case #1: 4 Case #2: 0
 

Source
 

題目大意:題目意思很簡單,只是當時真的不敢暴力啊,(10^5)^2。直接暴力寫出來了。。

題目地址:A Bit Fun

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


int main()
{
    int tes,i,j;
    int cas=0;
    scanf("%d",&tes);
    while(tes--)
    {
        int n,m;
        int res=0;
        scanf("%d%d",&n,&m);
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(i=0;i<n;i++)
        {
            int tmp=0;  //0|p=p
            for(j=i;j<n;j++)
            {
                 tmp=tmp|a[j];
                 if(tmp>=m)
                    break;
                 res++;
            }
        }
        printf("Case #%d: %d\n",++cas,res);
    }
    return 0;
}

//171MS 620K



相關文章