A 题: 说的是在(LR) 之间找出ab互质 bc 互质 ac 不互质的 3个数 数据量小直接暴力

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
return b==?a:(gcd(b,a%b));
}
int main()
{
ll L,R;
while(scanf("%I64d%I64d",&L,&R)==){
bool falg=false;
for(ll i=L; i<=R-; ++i){
for(ll j=i+; j<=R-; ++j){
ll f= gcd(i,j);
if(f!=) continue;
for(ll e = j+; e<=R; ++e){
f = gcd(e,j);
if(f!=) continue;
f=gcd(i,e);
if(f==) continue;
falg=true;
printf("%I64d %I64d %I64d\n",i,j,e);
break;
}
if(falg) break;
}
if(falg) break;
}
if(falg==false) puts("-1");
} return ;
}

B 题: 说的是找出cnt1 + cnt2 个质数然后 他们各不相同 cnt1 个不是x倍数的 cnt2 个不是y倍数的,分配完这些数后最大值最小

这样二分最大值,假设在mid 内 x 倍数为 px y的为py xy的为pxy 那么优先将 px-pxy的分给cnt2 把 py-pxy分给cnt1 这样接下来判段剩下的是否可以分配给cnt1和cnt2 剩余的 这样不断二分下去

#include <cstdio>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll cnt1,cnt2,x,y;
ll maxv(ll a, ll b){ return a>b?a:b; }
bool solve(ll mid){
ll a1 = mid/x;
ll b1 = mid/y;
ll c1 = mid/(x*y);
ll acnt1 = maxv(cnt1 - (b1-c1),0LL);
ll acnt2 = maxv(cnt2 - (a1-c1),0LL);
ll lest = mid-(a1+b1-c1);
if(lest>=(acnt1+acnt2)) return true;
else return false;
}
int main()
{ while(scanf("%I64d%I64d%I64d%I64d",&cnt1,&cnt2,&x,&y)==){
ll R = 9223372036854775807LL;
ll L=;
ll ans;
while(R>=L){
ll mid = (R+L)/;
if(solve(mid)){
ans=mid; R=mid-;
}else{
L=mid+;
}
}
printf("%I64d\n",ans);
}
return ;
}

C 题: 输的是给了n个数 你写出n的一个排列使得 相邻的数的差值有k个不同的值,然后这n个数必须是1—n 不能重复,这样不断的往两边取 直到有k个不同的

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
typedef long long ll;
const int maxn = ;
int ans[maxn];
set<int>Q;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)==){
int L=;
int num=;
int R=n+;
int now=;
ans[]=;
for(int i=; i<k; ++i){
now=-now;
if(now==){
L++;
ans[num]=L;
num++;
}else{
R--;
ans[num]=R;
num++;
}
}
if(num<n){
if(now==){
for(int i=R-; i>L; i--) ans[num++]=i;
}else{
for(int i=L+; i<R; i++) ans[num++]=i;
}
}
for(int i=; i<n; ++i){
printf("%d%c",ans[i],i==(n-)?'\n':' ');
}
} return ;
}

D题: 说的是给了n个数 m次操作 然后给了他们区间&后的值 这样问他们与后是否是合法的,我们知道给了区间& 的结果 也就是区间内的值每个都|上了这个值才能保证他们都具有相同的值

这样然后 将给的区间全部或上 q 然后 最后在按照 题目给的& 上一次 一旦出现与答案不符就证明是错误的

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn = ;
int cL,cR,W,b,n;
struct Itree{
int V[maxn*];
void pushdown(int o){
V[o*]|=V[o];
V[o*+]|=V[o];
V[o]=;
}
void build(int o, int L, int R){
if(L==R) return ;
pushdown(o);
int mid=(L+R)/;
build(o*,L,mid);
build(o*+,mid+,R);
V[o]=V[o*]&V[o*+];
}
void update(int o, int L, int R){
if(cL<=L&&R<=cR){
V[o]|=W;
return;
}
pushdown(o);
int mid=(L+R)/;
if(cL<=mid)
update(o*, L, mid);
if(cR>mid) update(o*+,mid+,R);
}
void query(int o, int L, int R){
if(cL<=L&&R<=cR){
if(b==)
W=V[o];
else W=W&V[o];
b=;
return ;
}
int mid=(L+R)/;
if(cL<=mid) query(o*,L,mid);
if(cR>mid) query(o*+,mid+,R);
}
void print(int o, int L, int R){
if(L==R){
printf("%d%c",V[o],L==n?'\n':' ');
return ;
}
int mid = (L+R)/;
print(o*, L, mid);
print(o*+,mid+,R);
}
}T;
int LL[maxn],RR[maxn],QQ[maxn];
int main()
{
int m;
while(scanf("%d%d",&n,&m)==){
memset(T.V,,sizeof(T.V));
for(int i=; i<m; ++i){
scanf("%d%d%d",&LL[i],&RR[i],&QQ[i]);
cL=LL[i];
cR=RR[i];
W=QQ[i];
T.update(,,n);
}
bool falg=true;
T.build(,,n);
for(int i=; i<m; ++i){
b=;
cL=LL[i];
cR=RR[i];
T.query(,,n);
if(QQ[i]!=W){
falg=false; break;
}
}
if(falg==false){
printf("NO\n");
}else {
printf("YES\n");
T.print(,,n);
}
}
return ;
}

E 题说的 你把每个串从其他串中区别出来的期望步数, 状态压缩live[S] 表示 S 这个状态中有多少个串需要在选字母,然后dp[S] 表示到达这个状态的概率 ,对于每个一个S 有相应的期望

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
double dp[<<];
char str[][];
long long live[<<];
int main()
{
int n;
while(scanf("%d",&n)==){
memset(live,,sizeof(live));
memset(dp,,sizeof(dp));
for(int i=; i<n; ++i){
scanf("%s",str[i]);
}
int m=strlen(str[]);
for(int i=; i<n; ++i){ for(int j=i+; j<n; ++j )
{
int S=;
for(int k=; k<m; ++k)
if(str[i][k]==str[j][k])
S|=(<<k);
live[S]|=(1LL<<i)|(1LL<<j);
}
}
for(int S = (<<m)-; S>; --S){
for(int i=; i<m; ++i)
if(S&(<<i)) live[S^(<<i)]|=live[S];
}
dp[]=;
double ans=;
for(int S=; S<<<m; ++S){
int num=;
for(int i=; i<n; ++i)
if(live[S]&(1LL<<i)) num++;
ans+=dp[S]*num;
num=;
for(int i=; i<m; ++i)
if(S&(<<i)) num++;
for(int i=; i<m; ++i)
if( (S&(<<i)) == )
dp[ S|(<<i) ]+= dp[S]/(m-num);
}
printf("%.15lf\n",ans/n);
}
return ;
}

Codeforces Round #275 (Div. 2) 题解的更多相关文章

  1. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  4. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

  5. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  6. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  7. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  8. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  9. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

随机推荐

  1. hadoop程序MapReduce之average

    需求:求多门课程的平均值. 样板:math.txt zhangsan 90 lisi 88 wanghua 80 china.txt zhangsan 80lisi 90wanghua 88 输出:z ...

  2. Redis(二)-- 发布订阅、事务、安全、持久化

    一.Redis发布订阅 Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. 打开两个窗口:session1 和 session2 在sess ...

  3. mac 操作idea快捷键

    http://blog.csdn.net/rainytooo/article/details/51469126 在mac下idea的常用快捷键如下,下面的快捷键都亲自试用,并有一些和eclipse对比 ...

  4. <linux系统c语言生成.so文件,生成64位可执行文件,在64位系统中运行32位的可执行文件>

    1.linux 系统c语言生成.o文件,---->gcc -m64 -c -fPIC test.c -o test.o2.linux 系统c语言生成.so文件,----->gcc -sha ...

  5. java生成webservice方法

    参考: https://note.youdao.com/ynoteshare1/index.html?id=c10324bb3b794baece3d2ae9faadc5c1&type=note

  6. 高中生的IT之路-1.2离开校园

    记得那是07年夏季的一天,高考成绩出来之后,班主任老师通知大家回学校报考志愿. 那天我刚到学校会议室,我还没来得及和同学见面就被班主任喊过去了,把志愿表递给我了我,我当时连仔细看那张志愿表都没看,随手 ...

  7. UINavigationController和UITabBarController

    UINavigationController和UITabBarController 目录 概述 UINavigationController UITabBarController 实用功能 待解决 概 ...

  8. .net asp iis服务器如何让外部访问自己的网站

    1.控制面板-防火墙-高级设置-入站规则-右侧的BranchCache内容检索,右键启用规则.  

  9. MVC之AJAX异步提交表单

    第一种用法: 在MVC中,依然可以使用ajax校验,跟在WebForm中的使用时一样的,唯一的区别就是将以前的URL路劲改为访问控制器下的行为 前台 <html> <head> ...

  10. TA-Lib中文文档(二):talib安装

    安装 使用pip安装 PyPI: $ pip install TA-Lib Or checkout the sources and run setup.py yourself: $ python se ...