[NWPU][2014][TRN][1]水题堆
7:30:00
//@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
//@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;
}