南华大学ACM新生赛第二场标程和数据 D-E

Problem B: Dating With Girls


Time Limit: 2 Sec  Memory Limit: 128 MB

Submit: 64  Solved: 23
[Submit][Status][Web Board]

Description

One day, Little Sheep gets an AK(all kill) in a contest, so he is very boring, then he just plays with a
paper. The paper has two faces called A and B. Sheep finds the paper can be folded for infinity times,
and now Sheep thinks the paper is interesting, so he tries to fold the paper in half for many times. He
finds out he has four way to make the paper folded in half, there are listed below:
At first, Little Sheep keeps the face A of the paper faced to him,and he fold the paper for many times.
In the end, Sheep opens up the paper, and keeps the face A faced to him again. Now the question is :
How many creases on the face A of the paper are protruding? God sheep solves the question without 2
seconds. Can you? You should make your answer mod 100000009.

Input

The first line of input contains a single positive integer N , which means the number of test cases.
The following N lines gives N non-empty strings containing only characters in ”UDLR”, which is the
sequences of the actions of the Sheep to fold paper. The length of the each string is a positive number
less than 10^6.

Output

For each case output the answer mod 100000009 in a line.

Sample Input

4LLRDLURULULL

Sample Output

011022

HINT


/*以左右折叠为例,每一次向左或者向右折叠一次,
竖着的折痕里边有对折后的纸总块数一半的折痕会凸出来
(每一次对折纸的总块数增加了1倍),
横着的折痕里边是已经凸出来的折痕的两倍
(这是因为横着的这横数变成了原来的2倍) 
*/



代码:
# include<stdio.h>
# include<string.h>
# include<math.h>
const int mod 100000009
 
int main()
{
    int T,len,i;
    long long a,b,tmp; 
    //a,b分别表示横着、竖着凸出的折痕,tmp表示总块数
    char s[1000005];
    scanf("%d",&T);
    while(T--){
        scanf("%s",s);
        len=strlen(s);
        a=b=0; tmp=1;
        for(i=0;i<len;i++)
        {
            if(s[i]=='L' || s[i]=='R'){
                b=(b+tmp/2)%mod;
                a=(a*2)%mod;
            }
            else
            {
                a=(a+tmp/2)%mod;
                b=(b*2)%mod;                
            }
            tmp *= 2;
            tmp = tmp%(2*mod);    //注意是2倍的
        }
        printf("%lld\n",(a+b)%mod);
    }
    return 0;
 }


Problem G: Matrix

Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 88   Solved: 15
[ Submit][ Status][ Web Board]

Description

To efficient calculate the multiplication of a sparse matrix is very useful in industrial filed. Let’s consider
this problem:
A is an N*N matrix which only contains 0 or 1. And we want to know the result of AA T.
Formally, we define B = AA T, Aij is equal to 1 or 0, and we know the number of 1 in matrix A is M
and your task is to calculate B.

Input

The input contains several test cases. The first line of input contains a integer C indicating the number
of the cases.
For each test case, the first line contains two integer N and M.
and each of next M lines contains two integer X and Y , which means Axyis 1.
N ≤ 100000, M ≤ 1000, C ≤ 10

Output

For each test case, it should have a integer W indicating how many element in Matrix B isn’t zero in one
line.

Sample Input

2
5 3
1 0
2 1
3 3
3 3
0 0
1 0
2 0

Sample Output

3
9


几乎全搬套用



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值