读书人

2013成都市网络赛 两个简单题

发布时间: 2013-09-15 19:58:13 作者: rapoo

2013成都网络赛 两个简单题

We Love MOE GirlsTime Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 205 Accepted Submission(s): 154


Problem DescriptionChikami 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?
InputThe 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.
OutputFor 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
2ohayougozaimasudaijyoubudesu

Sample Output
Case #1: ohayougozaimasunanodesuCase #2: daijyoubunanodesu

Source2013 ACM/ICPC Asia Regional Chengdu Online

题目地址:We Love MOE GirlsAC代码:
Problem DescriptionThere 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.
InputThe 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.
OutputFor 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
23 61 3 52 45 4

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

Source2013 ACM/ICPC Asia Regional Chengdu Online
题目大意:题目意思很简单,只是当时真的不敢暴力啊,(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



读书人网 >编程

热点推荐