A.3*3讨论即可,注意正方形套圆套三角形只有6个点。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,ans,a[N]; int main(){
scanf("%d",&n);
rep(i,,n) scanf("%d",&a[i]);
rep(i,,n){
if ((a[i-]== && a[i]==) || (a[i-]== && a[i]==)){ puts("Infinite"); return ; }
if ((a[i-]== && a[i]==) || (a[i-]== && a[i]==)) ans+=;
if ((a[i-]== && a[i]==) || (a[i-]== && a[i]==)) ans+=;
if (i>= && a[i-]== && a[i-]== && a[i]==) ans--;
}
printf("Finite\n%d\n",ans);
return ;
}

A

B.相同字符显然放在一起,先统计一共有几种字符。若一种,直接输出。若两种,若两字符相邻则无解否则直接输出。若三种,若三字符均相邻则无解,否则132或213总有一种可行。若四种,3142即可。四种以上,前一半和后一半间隔着输出即可。如n=6时输出142536。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
char s[N];
int T,n,cnt[N],w[N]; int main(){
for (scanf("%d",&T); T--; ){
scanf("%s",s+); n=strlen(s+); int d=;
rep(i,,) cnt[i]=;
rep(i,,n) cnt[s[i]-'a']++;
rep(i,,) if (cnt[i]) w[++d]=i;
if (d==){ puts(s+); continue; }
if (d==){
if (w[]+==w[]) puts("No answer");
else{
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a'); puts("");
}
continue;
}
if (d==){
if (w[]+==w[]){
if (w[]+==w[]) puts("No answer");
else{
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a'); puts("");
}
}else{
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a'); puts("");
}
continue;
}
if (d==){
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a');
rep(i,,cnt[w[]]) putchar(w[]+'a');
puts("");
continue;
}
rep(i,,(d+)/){
rep(j,,cnt[w[i]]) putchar(w[i]+'a');
if (i+(d+)/<=d) rep(j,,cnt[w[i+(d+)/]]) putchar(w[i+(d+)/]+'a');
}
puts("");
}
return ;
}

B

C.二分答案,设二分值为mid,则将i和n-mid+i依次配对,判断配对数是否>=mid。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,z,ans,a[N],b[N]; bool chk(int mid){
int res=;
rep(i,,mid) if (a[n-mid+i]-a[i]>=z) res++;
return res>=mid;
} int main(){
scanf("%d%d",&n,&z);
rep(i,,n) scanf("%d",&a[i]);
sort(a+,a+n+); int L=,R=n/;
while (L<R){
int mid=(L+R+)>>;
if (chk(mid)) L=mid; else R=mid-;
}
printf("%d\n",L);
return ;
}

C

D.一种方法是,先对每个点BFS出它所在1连通块的大小bel[x],然后再对每个点BFS出它所在0连通块并将块中的点的bel累加起来得到答案。

还有一种是树上DP,f[x][0/1]表示x往下只走0边/先走0边再走1边,的方案数。g[x][0/1]表示x往下只走1边/先走1边再走0边,的方案数。在每个点上枚举有多少以它为路径最高点的合法路径。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=; int n,p[N],t;
ll f[N][],g[N][],ans;
struct data{int to,nxt,len; }E[N<<];
void add(int x,int y,int z){t++;E[t].to=y,E[t].nxt=p[x],E[t].len=z,p[x]=t;} void dfs(int k,int from){
f[k][]=; g[k][]=;
for (int i=p[k];i;i=E[i].nxt)
if (E[i].to!=from){
dfs(E[i].to,k);
if (E[i].len==) f[k][]+=f[E[i].to][];
else f[k][]+=f[E[i].to][]+f[E[i].to][];
if (E[i].len==) g[k][]+=g[E[i].to][];
else g[k][]+=g[E[i].to][]+g[E[i].to][];
}
for (int i=p[k];i;i=E[i].nxt)
if (E[i].to!=from){
int x=f[k][],y=f[k][];
if (E[i].len==) x-=f[E[i].to][];
else y-=f[E[i].to][]+f[E[i].to][];
if (E[i].len==) ans+=x*g[E[i].to][];
ans+=x*g[E[i].to][];
if (E[i].len==) ans+=y*g[E[i].to][];
}
ans+=f[k][]+f[k][]-;
} int main(){
scanf("%d",&n);
rep(i,,n){
int x,y,z; scanf("%d%d%d",&x,&y,&z);
add(x,y,z),add(y,x,z);
}
dfs(,); cout<<ans<<endl;;
return ;
}

方法二

E.从小到大插入p,每次以当前p[x]为区间最大值的合法区间数,就是x左边的已插入的连续段和右边已插入的连续段的信息合并。这个可以用set启发式合并支持查询与合并,为了快速寻找某个位置被合并到哪了需要用到并查集,复杂度两个log。

 #include<set>
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int N=;
int n,ans,a[N],id[N],fa[N];
set<int>S[N]; bool cmp(int x,int y){ return a[x]<a[y]; }
int get(int x){ return fa[x]==x ? x : fa[x]=get(fa[x]); } int main(){
scanf("%d",&n);
rep(i,,n) scanf("%d",&a[i]),id[i]=fa[i]=i,S[i].insert(a[i]);
sort(id+,id+n+,cmp);
rep(i,,n){
int x=id[i],p=get(x-),q=get(x+);
if (x== || x==n || a[x-]>a[x] || a[x+]>a[x]){
if (x> && a[x-]<a[x]) S[p].insert(a[x]),fa[x]=p;
if (x<n && a[x+]<a[x]) S[q].insert(a[x]),fa[x]=q;
continue;
}
if (S[p].size()>S[q].size()) swap(p,q);
set<int>::iterator it;
for (it=S[p].begin(); it!=S[p].end(); it++)
if (S[q].find(a[x]-(*it))!=S[q].end()) ans++;
for (it=S[p].begin(); it!=S[p].end(); it++) S[q].insert(*it);
S[q].insert(a[x]); fa[p]=fa[x]=q;
}
printf("%d\n",ans);
return ;
}

E

F.枚举win的时候是第几次拿数以及这个数是几。f[i][j]表示数j作为第i个拿出来的数且前i个数都严格递增的概率。根据这个再要求第i+1个数也为j,再之后的数随便放即可。

 #include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int N=,mod=;
int n,x,ans,f[N][N],cnt[N],inv[N]; int main(){
scanf("%d",&n); inv[]=;
rep(i,,n) scanf("%d",&x),cnt[x]++;
rep(i,,n) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
rep(i,,n){
int s=(i==);
rep(j,,n){
f[i][j]=1ll*s*cnt[j]%mod*inv[n-i+]%mod;
if (cnt[j]>) ans=(ans+1ll*f[i][j]*(cnt[j]-)%mod*inv[n-i]%mod)%mod;
s=(s+f[i-][j])%mod;
}
}
printf("%d\n",ans);
return ;
}

F

Educational Codeforces Round 64 (Div. 2)的更多相关文章

  1. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  2. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  3. Educational Codeforces Round 64(ECR64)

    Educational Codeforces Round 64 CodeForces 1156A 题意:1代表圆,2代表正三角形,3代表正方形.给一个只含1,2,3的数列a,ai+1内接在ai内,求总 ...

  4. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  5. Educational Codeforces Round 84 (Div. 2)

    Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...

  6. Educational Codeforces Round 64 (Rated for Div. 2) A,B,C,D,E,F

    比赛链接: https://codeforces.com/contest/1156 A. Inscribed Figures 题意: 给出$n(2\leq n\leq 100)$个数,只含有1,2,3 ...

  7. Educational Codeforces Round 64 (Rated for Div. 2) (线段树二分)

    题目:http://codeforces.com/contest/1156/problem/E 题意:给你1-n  n个数,然后求有多少个区间[l,r] 满足    a[l]+a[r]=max([l, ...

  8. Educational Codeforces Round 64 (Rated for Div. 2)D(并查集,图)

    #include<bits/stdc++.h>using namespace std;int f[2][200007],s[2][200007];//并查集,相邻点int find_(in ...

  9. Educational Codeforces Round 64(Unrated for Div.1+Div. 2)

    什么垃圾比赛,A题说的什么鬼楞是没看懂.就我只会BD(其实C是个大水题二分),垃圾游戏,技不如人,肝败吓疯,告辞,口胡了E就睡觉了. B 很容易发现,存在一种方案,使得相同字母连在一起,然后发现,当字 ...

随机推荐

  1. SonarQube入门【转】

    一.SonarQube简介Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Sonar可以集成不同的测试工具,代码分析工具, 以及持续集成工具. 比如pmd-cpd.checkstyle.f ...

  2. GPS 经纬度

      经纬度地图: http://www.gpsspg.com/maps.htm http://www.gzhatu.com/dingwei.html 经纬度格式转化 http://www.gzhatu ...

  3. Flutter -------- Http库实现网络请求

    第三方库 http实现网络请求,包含get,post http库文档:https://pub.dev/packages/http 1.添加依赖 dependencies: http: ^0.12.0 ...

  4. Visual Studio 2019更新到16.2.3

    Visual Studio 2019更新到16.2.3   此次更新,包括以下内容: (1)修复找不到Android SDK的bug. (2)修复安装结束后,无法启动的bug. (3)修复关闭VS时, ...

  5. Python中产生随机数

    Python中产生随机数 一.Python自带的random库       1.参生n--m范围内的一个随机数:    random.randint(n,m) 2.产生0到1之间的浮点数:  rand ...

  6. SUPERSOCKET.CLIENTENGINE 简单使用

    首先 引用 SuperSocket.ClientEngine.Core.dll和 SuperSocket.ClientEngine.Common.dll 然后 就可以使用ClientEngine了. ...

  7. k8s记录-kubeadm安装(一)(转载)

    配置 kubeadm 概述 安装 kubernetes 主要是安装它的各个镜像,而 kubeadm 已经为我们集成好了运行 kubernetes 所需的基本镜像.但由于国内的网络原因,在搭建环境时,无 ...

  8. python flask框架学习(一)——准备工作和环境配置与安装

    Flask装备: 学习自:知了课堂Python Flask框架——全栈开发 1.Python版本:3.6 2.Pycharm软件: 3.安装虚拟环境: (1)安装virtualenv: pip ins ...

  9. Python - Django - 上传文件

    upload.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  10. LeetCode_206. Reverse Linked List

    206. Reverse Linked List Easy Reverse a singly linked list. Example: Input: 1->2->3->4-> ...