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. c++ 函数后面加一个冒号的含义

    转载自:https://zhidao.baidu.com/question/2010930169328038188.html 冒号后面跟的是赋值,这种写法是C++的特性. A( int aa, int ...

  2. MATLAB中 H(b > g) = 2*pi - H(b > g); 作何解

    H(b > g) = 2*pi - H(b > g); %b > g 会得到一个逻辑矩阵,如b=[7,5,6] ;g=[1,2,8],那么b>g会得到[1,1,0]: b< ...

  3. wrod: 突然无法输入汉字

    “文件”-“选项”-“高级”-“去掉 输入法控制处于活动状态复选框”.

  4. Dart中的mixins

    /* mixins的中文意思是混入,就是在类中混入其他功能. 在Dart中可以使用mixins实现类似多继承的功能,with关键字 因为mixins使用的条件,随着Dart版本一直在变,这里讲的是Da ...

  5. openresty开发系列13--lua基础语法2常用数据类型介绍

    openresty开发系列13--lua基础语法2常用数据类型介绍 一)boolean(布尔)布尔类型,可选值 true/false: Lua 中 nil 和 false 为"假" ...

  6. shell编程系列19--文本处理三剑客之awk中的字符串函数

    shell编程系列19--文本处理三剑客之awk中的字符串函数 字符串函数对照表(上) 函数名 解释 函数返回值 length(str) 计算字符串长度 整数长度值 index(str1,str2) ...

  7. Python 保存数据的方法:

    open函数保存 使用with open()新建对象 写入数据(这里使用的是爬取豆瓣读书中一本书的豆瓣短评作为例子) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  8. Java Class与反射相关的一些工具类

    package com.opslab.util; import org.apache.log4j.Logger; import java.io.File;import java.io.IOExcept ...

  9. Python 初级 5 判断再判断

    复习: 1 三种数据类型: 整数:int, (1, 2, 200) 浮点数: float(2.0, 9.5, 100.38) 字符串: str("小明", "abc&qu ...

  10. [Log4j使用教程] JavaSE/JavaEE/SpringMVC中使用Log4j

    要想使用Log4j, 首先需要下载到Log4j的jar, Download: http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log ...