codeforces Gym 100814 A、B、F、I
A题 先求出来这个数是第几大 阶乘求概率p 然后计算获得胜率的概率 常规解法把所有情况考虑一遍(跳1次,2次,3次……)要用到组合数 数可能太大了会爆的行不通
我们观察发现它有递推性质,从第二大开始获胜概率为Q1=p(直接跳到第一大)从第三大开始获胜概率为Q2=p*Q1(先跳到第二大)+p(直接跳到第一大)以此类推Q3=Q2*p+Q1*p+p
Q4=Q3*p+Q2*p+Q1*p+p 但是我们按照上面的递推式计算Qn时复杂度为O(n*n) 我们再改进一下Q2=Q1*(1+p),Q3=Q2*(1+p) ,Q4=Q3*(1+p)这样复杂度就为 O(n) 了
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
const int maxn = 2e2+;
const int maxm = 1e6+;
const int inf = 0x3f3f3f3f;
const double epx = 1e-;
typedef long long ll;
int a[maxn],b[maxn],c[maxn];
double f[maxm];
int main()
{
int t,n;
b[]=;
for(int i=;i<=;i++)
b[i]=b[i-]*i;
cin>>t;
while(t--)
{
cin>>n;
int cnt=;
while(n!=)
{
c[++cnt]=n%;
a[n%]++;
n/=;
}
reverse(c+,c+cnt+);
int sum=;
for(int i=;i<=cnt;i++)
{
for(int j=;j>=;j--)
{
if(a[j]>)
{
if(j>c[i])
sum+=b[cnt-i];
else if(j==c[i])
{
a[j]--;
break;
}
}
}
}
double p=1.0/b[cnt];
if(sum==)
f[]=;
else
{
f[sum-]=p;
for(int i=sum-; i>=; i--)
{
f[i]=f[i+]*p+f[i+];
}
}
printf("%.9lf\n",f[]);
}
}
B题 直接模拟 我写的是最暴力的那种。。。
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
const int maxn= 2e2+;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int main()
{
int t,n,m;
while(cin>>t)
{
while(t--)
{
char a[maxn][maxn];
char ans[maxn];
cin>>n>>m;
char x,y;
for(int i=;i<=m;i++)
{
for(int j=;j<=*n;j++)
{
cin>>a[i][j];
}
}
for(int i=;i<*n;i=i+)
{
int cnt1=,cnt2=,cnt3=,cnt4=;
int flag=;
for(int j=;j<=m;j++)
{
if(a[j][i+]=='T')
{
ans[i/+]=a[j][i];
flag=;
break;
}
else
{
if(a[j][i]=='A')
cnt1++;
else if(a[j][i]=='B')
cnt2++;
else if(a[j][i]=='C')
cnt3++;
else if(a[j][i]=='D')
cnt4++;
}
}
if(flag==)
{
if(cnt1>&&cnt2>&&cnt3>)
ans[i/+]='D';
else if(cnt1>&&cnt2>&&cnt4>)
ans[i/+]='C';
else if(cnt1>&&cnt3>&&cnt4>)
ans[i/+]='B';
else if(cnt2>&&cnt3>&&cnt4>)
ans[i/+]='A';
else
ans[i/+]='?';
}
}
for(int i=;i<=n-;i++)
printf("%c ",ans[i]);
printf("%c\n",ans[n]);
}
}
}
F题 水~~
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
const int maxn= 1e3+;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int n,m;
int a[maxn];
int main()
{
while(cin>>n)
{
int a,b;
while(n--)
{
cin>>a>>b;
if(a==b)
printf("Square\n");
else
printf("Rectangle\n");
}
}
}
I题 n比较小直接枚举组合情况 一位一位比较记录第一次和最后一次不同的位置,直接异或也可以
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
const int maxn= 1e3+;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int n,m;
int a[maxn];
int main()
{
int t;
while(cin>>t)
{
while(t--)
{
cin>>n;
for(int i=; i<=n; i++)
cin>>a[i];
sort(a+,a++n);
int ans=-;
for(int i=; i<n; i++)
{
for(int j=i+; j<=n; j++)
{
int num=;
int tempi=a[i],tempj=a[j];
int cnt=;
while(tempi!=)
{
int ki=tempi&;
int kj=tempj&;
if(ki!=kj)
{
num++;
}
tempi=tempi>>;
tempj=tempj>>;
cnt++;
}
while(tempj!=)
{
if(tempj&)
{
num++;
}
tempj=tempj>>;
cnt++;
}
//printf("%d %d %d\n",a[i],a[j],num);
ans=max(ans,num);
}
}
cout<<ans<<endl;
}
}
}
codeforces Gym 100814 A、B、F、I的更多相关文章
- codeforces gym/100814 humming distance (二进制位数比较)
Gym - 100814I I. Salem time limit per test 1 second memory limit per test 1024 megabytes input stand ...
- AT NEW F、AT END OF F注意事项
1.F只能是内表的第一个字段 2.AT NEW F.AT END OF F使用F之后内表内容会变为* 解决出现*的办法: FIELD-SYMBOLS:<ITAB> LIKE ITAB L ...
- <转>thinkphp的各种内部函数 D()、F()、S()、C()、L()、A()、I()详解
D.F.S.C.L.A.I 他们都在functions.php这个文件家下面我分别说明一下他们的功能 D() 加载Model类M() 加载Model类 A() 加载Action类L() 获取语言定义C ...
- ThinkPHP内置函数详解D、F、S、C、L、A、I
单字母函数D.F.S.C.L.A.I 他们都在ThinkPHP核心的ThinkPHP/Mode/Api/functions.php这个文件中定义. 下面我分别说明一下他们的功能: D() 加载Mode ...
- 对C标准中空白字符(空格、回车符(\r)、换行符(\n)、水平制表符(\t)、垂直制表符(\v)、换页符(\f))的理解
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] C标准库里<ctype.h>中声明了一个函数: int isspace(int c); 该函数判断字符c是否 ...
- ORM之自关联、add、set方法、聚合函数、F、Q查询和事务
一.外键自关联(一对多) 1.建表 # 评论表 class Comment(models.Model): id = models.AutoField(primary_key=True) content ...
- 机器学习算法中的准确率(Precision)、召回率(Recall)、F值(F-Measure)
摘要: 数据挖掘.机器学习和推荐系统中的评测指标—准确率(Precision).召回率(Recall).F值(F-Measure)简介. 引言: 在机器学习.数据挖掘.推荐系统完成建模之后,需要对模型 ...
- 2、函数y=f(x)
/* Note:Your choice is C IDE */ #include "stdio.h" /* 3.函数y=f(x)可表示为: */ void main() { int ...
- Django 08 Django模型基础3(关系表的数据操作、表关联对象的访问、多表查询、聚合、分组、F、Q查询)
Django 08 Django模型基础3(关系表的数据操作.表关联对象的访问.多表查询.聚合.分组.F.Q查询) 一.关系表的数据操作 #为了能方便学习,我们进入项目的idle中去执行我们的操作,通 ...
随机推荐
- php安装ionCube
- hihocoder编程练习赛52-2 亮灯方案
思路: 状态压缩dp.实现: #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ] = {, , ...
- C#中的事件机制
这几天把事件学了一下,总算明白了一些.不多说了,直接代码. class Program { static void Main(string[] args) { CatAndMouse h = new ...
- 【C++】异常简述(三):补充之如何看待C++异常
C++异常的使用,我相信在上文总结的已经比较完整了,本文主要对C++异常这块进行额外的补充. 即使C++将异常纳入标准已经很多年了,但是直到现在都能看到很多坚持不显式使用异常.(包括本人在内,在写的代 ...
- 使用VC++编写QQ群发器,MFC做UI
由于公司业务需要,QQ群发器经常被用来发送QQ广告,购买的QQ群发器不好用不说,而且是按机器收费的,有些功能还不能修改. 所以公司派我来开发一款自己的QQ群发器,我给群发器取名叫做飞速群发器,用来给软 ...
- Vue路由模式及监听
当然详细情况还是看一下vue的官网吧 官网https://router.vuejs.org/zh/ hash模式下(默认) new VueRouter({ mode : ‘hash’, route ...
- PHP-碎片知识 $_SERVER['argv']
1.cli模式(命令行)下,第一个参数$_SERVER['argv'][0]是脚本名,其余的是传递给脚本的参数 2.web网页模式下 在web页模式下必须在php.ini开启register_argc ...
- BZOJ1079: [SCOI2008]着色方案 (记忆化搜索)
题意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块. 所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得很 ...
- jquery.data.resource.js
/*! * jQeury Data Pkugin * version: 1.0.0-2016.03.03 * Requires jQuery v1.10.2 or later * Copyright ...
- 题解 洛谷P2147/BZOJ2049【[SDOI2008]洞穴勘测】
Link-Cut-Tree的模板题啊......(听说还可以用其他的方法做,不管了,直接上LCT) 没有要求维护点权,只需要维护点的连通性即可. 就是朴素的LCT,居然还不要pushup. 感觉有些不 ...