poj 1936

[NWPU][2014][TRN][1]水题堆
7:30:00
                   
C - All in All
Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

Description

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. 

Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s. 

Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

Output

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>

using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 1100000;
const int INF = 2100000000;
string s1, s2;


int main()
{
//    freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
    while(cin >> s1 >> s2)
    {
        int lens1 = s1.length(), lens2 = s2.length();
        int cnt = 0, k = 0;
        int j = 0;
        //此处j设为全局变量比较简单
        for(int i = 0; i < lens1; i++)
        {
            for( ; j < lens2; j++)
            {
                if(s1[i] == s2[j])
                {
                    cnt++;
                    j++;break;
                }
            }
        }
        if(cnt == lens1)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
[NWPU][2014][TRN][1]水题堆
7:30:00
F - 湫湫系列故事――植树节
Time Limit:500MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u

Description

  今天是一年一度的植树节,腾讯幼儿园要求每个老师在班里选出几个小朋友一起去野外种植小树苗,根据学校的整体安排,湫湫老师的班里要选出3个小朋友。  已知湫湫的班里共有n个孩子,每个孩子有Bi个朋友(i从1到n),且朋友关系是相互的,如果a小朋友和b小朋友是朋友,那么b小朋友和a小朋友也一定是好朋友。为了选择的公平性,湫湫老师会随机抽取3个小朋友出来(每个人被抽到的概率相同),但是她很希望这3个小朋友之间的关系完全相同,湫湫老师想请你帮她算算抽到的3个小朋友正好关系相同的概率是多少?
  PS. 关系相同就是指要么3个人互相是好朋友,要么3个人互相都不是好朋友。
 

Input

输入数据第一行是一个整数T(1<=T<=1000),表示输入数据的组数;每组数据的第一行是一正整数n表示孩子的总数(2<n<=1000),第二行有n个数Bi (i从1到n),分别代表每个小朋友的朋友的个数。
 

Output

对于每组数据,请输出抽到的3个小朋友关系相同的概率,结果保留3位小数。
 

Sample Input

         
         
1 5 3 3 3 3 4
 

Sample Output

         
         
0.400
 


//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 1100000;
const int INF = 2100000000;
int T, n, b;
/*这题的解法就是从不符合条件人手,不符合的情况一定是其中有两个人是朋友,
另个人至少和其中一个人不是朋友,这样对于每个小朋友,我们把他看成是
那两个人是朋友中的一个从而来构成不符合条件的组合,则共有bi*(n-bi-1)种组合,
再由于每种组合里有两个人是朋友,所以每个组合被计算了两次,求和的结果除以二
就是不符合条件的组合数。*/

int main()
{
//    freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
    scanf("%d",&T);
    while(T--)
    {
        int tot = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &b);
            tot += (b*(n-1-b));
        }
        printf("%.3f\n", 1.0 - tot*0.5/((1.0*n*(n-1)*(n-2)/6.0)));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值