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# WinForm MessageBox弹窗倒计时的自动关闭

    [DllImport("user32.dll", EntryPoint = "FindWindow")]        private static exter ...

  2. https://software.intel.com/sites/landingpage/pintool/docs/97998/Pin/html/

    https://software.intel.com/sites/landingpage/pintool/docs/97998/Pin/html/   http://www.brendangregg. ...

  3. iptables 配置 场景1

    这样配置完成后,没法完成本地回环,需要对lo网卡进行配置 本地报文无法发出,继续添加规则

  4. 【转载】 linux系统dig和nslookup的安装

    原文地址: https://blog.csdn.net/bjbs_270/article/details/7003088 --------------------------------------- ...

  5. osg::Node clone

    深度拷贝 node.clone(osg::CopyOp::DEEP_COPY_ALL)  osg::ref_ptr<osg::Node> deepnode = (osg::Node *)( ...

  6. osg坐标位置转换

    osg::Vec3f vec3f1 = hookNode->getBound().center(); osg::NodePathList nodePAthList1 = hookNode-> ...

  7. Error:java: 发现警告, 但指定了 -Werror

    最近在使用IntelliJ IDEA编译Apache Guacamole Web项目时,遇到了一个罕见的bug:"Error:java: 发现警告, 但指定了 -Werror",见 ...

  8. redis和memcache对比

    1.性能方面:没有必要过多的关心性能,因为二者的性能都已经足够高了.由于Redis只使用单核,而Memcached可以使用多核,所以在比较上,平均每一个核上Redis在存储小数据时比Memcached ...

  9. jQuery调用WebService返回JSON数据

    相信大家都比较了解JSON格式的数据对于ajax的方便,不了解的可以从网上找一下这方面的资料来看一下,这里就不多说了,不清楚的可以在网上查一下,这里只说一下因为参数设置不当引起的取不到返回值的问题. ...

  10. Sublime Text3安装及常用插件安装

    为了使用强大好用的代码编辑器来进行selenium3+Python3的自动化测试. 使用Sublime Text 3非常适合. 1.下载安装 首先到http://www.sublimetext.com ...