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. 新零售下的 AI智能货柜

    公司有个智能货柜,通过微信扫码开门,拿货,自动扣款,挺智能的.还不错.研究一下原理,网上查了一下. 文章简介: 目前新零售风刮的蛮大,笔者进入该领域近一年,负责过无人便利店.智能货柜.智慧商超等产品, ...

  2. 【Json】Json分词器

    package com.hy; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNo ...

  3. flutter -------- 页面跳转和传值

    在安卓原生开发中,页面跳转可以用Intent类来具体实现: Intent intent =new Intent(MainActivity.this,second.class); startActivi ...

  4. Linux Nginx naxsi

    nginx naxsi 模块 - 简书https://www.jianshu.com/p/8492da04b3ba naxsi compile · nbs-system/naxsi Wikihttps ...

  5. AI学习网址记录

    https://ai.yanxishe.com/ https://ai.yanxishe.com/page/blogDetail/14365 GAN网络 对抗式生成网络-图像超分辨及图像修复 完全可见 ...

  6. GPRS以TCP上传数据到服务器OK,但收不到服务器下发的数据

    GPRS以TCP上传数据到服务器OK,但收不到服务器下发的数据 基站漂移是DTU很常见的连接故障,一个DTU所处的地方可能会有多个基站信号,时间久了,可能会在不同的基站之间切换,它会更新自己的连接,发 ...

  7. Java 13 特性解读

    Java 13 特性解读    转 https://blog.csdn.net/bjweimengshu/article/details/100978383   2017年8月,JCP执行委员会提出将 ...

  8. vscode 常用设置与插件推荐

    1.Chinese (Simplified) Language Pack for Visual Studio Code 适用于 VS Code 的中文(简体)语言包 2.Color Info Visu ...

  9. Vue绑定属性 绑定Class 绑定style

    <template> <div id="app"> <h2>{{msg}}</h2> <br> <div v-bi ...

  10. ISO/IEC 9899:2011 条款5——5.1 概念模型

    5.1 概念模型 5.1.1 翻译环境 5.1.2 执行环境