Educational Codeforces Round 63 Div. 2
A:找到两个相邻字符使后者小于前者即可。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n;char s[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();scanf("%s",s+1);
int x=0;
for (int i=2;i<=n;i++) if (s[i]<s[i-1]) {x=i;break;}
if (x==0) cout<<"NO";
else cout<<"YES"<<endl<<x-1<<' '<<x;
return 0;
//NOTICE LONG LONG!!!!!
}
B:设(n-11)/2=x,8的出现次数=y。显然x>=y时,后手一直拿8就可以阻止先手取胜。考虑x<y的情况,后手的最优策略仍然是一直拿最靠前的8,而先手应该拿最靠前的非8的数。于是找到第x+1个8的位置check一下。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n;char s[N];
signed main()
{
n=read();scanf("%s",s+1);
int cnt=0;for (int i=1;i<=n;i++) if (s[i]=='8') cnt++;
if ((n-11)/2>=cnt) {cout<<"NO";return 0;}
cnt=(n-11)/2;
for (int i=1;i<=n;i++)
if (s[i]=='8')
{
cnt--;
if (cnt==-1)
{
if (i-1<=n-11) cout<<"YES";
else cout<<"NO";
break;
}
}
return 0;
//NOTICE LONG LONG!!!!!
}
C:a相邻作差取gcd,看b中是否有gcd的因子。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
ll gcd(ll n,ll m){return m==0?n:gcd(m,n%m);}
ll read()
{
ll x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m;
ll a[N],b[N];
signed main()
{
n=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=m;i++) b[i]=read();
sort(a+1,a+n+1);
ll u=0;
for (int i=2;i<=n;i++) u=gcd(u,a[i]-a[i-1]);
for (int i=1;i<=m;i++)
if (u%b[i]==0)
{
cout<<"YES"<<endl;
cout<<a[1]<<' '<<i;
return 0;
}
cout<<"NO";
return 0;
//NOTICE LONG LONG!!!!!
}
D:显然修改的子串一定会被选入答案,这样序列可以被分为五部分,即不被选入答案→被选入答案但不修改→被选入答案且修改→被选入答案但不修改→不被选入答案。可以整一些前缀和,但写起来可能有点麻烦。更简单的做法是f[i][0/1/2/3/4]表示当前在哪个阶段。https://www.cnblogs.com/Gloid/p/10358542.html受这一场的D启发。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
ll gcd(ll n,ll m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N];
ll ans,s[N],ssuf[N],pre[N],suf[N],f[N][5];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read();
memset(f,200,sizeof(f));
for (int j=0;j<5;j++) f[0][j]=0;
for (int i=1;i<=n+1;i++)
{
for (int j=0;j<5;j++)
for (int k=0;k<=j;k++)
f[i][j]=max(f[i][j],f[i-1][k]);
f[i][1]+=a[i];
f[i][2]+=1ll*a[i]*m;
f[i][3]+=a[i];
}
cout<<f[n+1][4];
}
E:写着脸上的拉格朗日插值。直接代入求值会T,先求出多项式即可。或者也可以高斯消元。所以询问次数是用来干啥的?
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define P 1000003
#define N 1000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
ll gcd(ll n,ll m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int a[20],Inv[P],f[20],g[20];
int inv(int a){return Inv[a];}
/*int calc(int n,int x)
{
int ans=0;
for (int i=0;i<n;i++)
{
int u=1;for (int j=0;j<n;j++) if (i!=j) u=1ll*u*(P+i-j)%P;
u=1ll*a[i]*inv(u)%P;
for (int j=0;j<n;j++) if (i!=j) u=1ll*u*(P+x-j)%P;
ans=(ans+u)%P;
}
return ans;
}*/
int calc(int x)
{
int s=f[11];
for (int i=10;i>=0;i--) s=(1ll*s*x+f[i])%P;
return s;
}
signed main()
{
Inv[0]=Inv[1]=1;for (int i=2;i<P;i++) Inv[i]=P-1ll*(P/i)*Inv[P%i]%P;
for (int i=0;i<12;i++)
{
cout<<"?"<<' '<<i<<endl;
a[i]=read();
}
for (int i=0;i<12;i++)
{
memset(g,0,sizeof(g));g[0]=1;
for (int j=0;j<12;j++)
if (i!=j)
{
for (int k=0;k<12;k++) g[k]=1ll*g[k]*inv((i-j+P)%P)%P;
for (int k=11;k>=1;k--) g[k]=(g[k-1]-1ll*g[k]*j%P+P)%P;
g[0]=(P-1ll*g[0]*j%P)%P;
}
for (int j=0;j<12;j++) f[j]=(f[j]+1ll*g[j]*a[i])%P;
}
for (int i=0;i<P;i++)
if (calc(i)==0) {cout<<"!"<<' '<<i<<endl;return 0;}
cout<<"!"<<' '<<-1<<endl;
return 0;
//NOTICE LONG LONG!!!!!
}
F:怎么感觉这么经典!哇我好像做过原题!https://www.cnblogs.com/Gloid/p/10291212.html 这个题一方面去掉了边权且没有重边,一方面要输出方案。前者当然是喜大普奔,不用判一些乱七八糟的情况了。后者求出dp数组后递归输出即可,在预处理能否串成链时记录一下串成的链是怎样的。复杂度O(2n*n3+3n*n2),但这个dp的常数一看就优秀的没边。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 14
#define M 1000
#define inf 100000000
#define rep(i,t,S) for (int t=S,i=lg2[t&-t];t;t^=t&-t,i=lg2[t&-t])
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N][N],f[1<<N],size[1<<N],lg2[1<<N];
bool g[N][N][1<<N];
int way[N][N][1<<N][N+1];
struct data{int x,y,z;
}edge[M];
void print(int S)
{
if (size[S]==1) return;
for (int i=S-1&S;i;i=i-1&S)
rep(x,u,i^S) rep(y,v,i^S)
{
if (g[x][y][i]&&f[i^S]+size[i]+1==f[S])
{
cout<<y+1<<' '<<way[x][y][i][1]+1<<endl;
for (int t=1;t<way[x][y][i][0];t++) cout<<way[x][y][i][t]+1<<' '<<way[x][y][i][t+1]+1<<endl;
cout<<way[x][y][i][way[x][y][i][0]]+1<<' '<<x+1<<endl;
print(i^S);
return;
}
if (x==y) break;
}
}
int main()
{
n=read(),m=read();
for (int i=1;i<=m;i++)
{
edge[i].x=read()-1,edge[i].y=read()-1,edge[i].z=1;
g[edge[i].x][edge[i].y][0]=g[edge[i].y][edge[i].x][0]=1;
}
memset(f,42,sizeof(f));for (int i=0;i<n;i++) f[1<<i]=0,lg2[1<<i]=i;
for (int i=1;i<(1<<n);i++) size[i]=size[i^(i&-i)]+1;
for (int i=1;i<(1<<n);i++)
{
rep(x,p,(1<<n)-1^i) rep(y,q,(1<<n)-1^i)
if (x!=y||i!=(i&-i)) rep(j,o,i)
if (g[j][y][i^(1<<j)]&&g[x][j][0])
{
g[x][y][i]=1;
for (int u=0;u<=way[j][y][i^(1<<j)][0];u++) way[x][y][i][u]=way[j][y][i^(1<<j)][u];
way[x][y][i][++way[x][y][i][0]]=j;
break;
}
}
for (int i=1;i<(1<<n);i++)
for (int j=i-1&i;j;j=j-1&i)
rep(x,u,i^j) rep(y,v,i^j)
{
if (g[x][y][j]&&f[i^j]+size[j]+1<f[i]) f[i]=f[i^j]+size[j]+1;
if (x==y) break;
}
printf("%d\n",f[(1<<n)-1]);
print((1<<n)-1);
return 0;
}
小小号打的。result:rank 1 rating +297 精准的没有超过小号(
Educational Codeforces Round 63 Div. 2的更多相关文章
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...
- Educational Codeforces Round 84 (Div. 2)
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...
- Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)
题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...
- Educational Codeforces Round 63 (Rated for Div. 2) E 带模高斯消元
https://codeforces.com/contest/1155/problem/E 题意 \(f(x)=a_0+a_1x+a_2x^2+...+a_kx^k,k \leq 10,0 \leq ...
- Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)
https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...
- Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维
题意:博弈题面 给出一个数字序列 (>=11) 有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手 数字序列一定是奇 ...
- Educational Codeforces Round 63 (Rated for Div. 2) C. Alarm Clocks Everywhere gcd
题意:给出一个递增的时间序列a 给出另外一个序列b (都是整数) 以b中任选一个数字作为间隔 自己从1开始任选一个时间当成开始时间 输出选择的数字标号以及 开始时间 思路 直接求间隔的公共gc ...
随机推荐
- 痞子衡嵌入式:开启NXP-MCUBootUtility工具的HAB签名功能 - CST(中英双语)
1 Reason for enabling HAB signature function 为什么要开启HAB签名功能 NXP-MCUBootUtility is a tool designed for ...
- Java并发编程系列-AbstractQueuedSynchronizer
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/10566625.html 一.概述 AbstractQueuedSynchronizer简 ...
- fuzzing学习
1.简介 1.1 fuzzing 模糊测试(fuzzing)是一种通过向程序提供非预期的输入并监控输出中的异常来发现软件中的故障的方法. 用于模糊测试的模糊测试器(fuzzer)可以按照以下3种方式进 ...
- AspNetCore+Swagger 生成Model 描述
AspNetCore+Swagger 生成Model 描述 前言: 本篇文章实现是基于上一篇文章,进下补充:多余的就不多说了,只是为了实现Model的描述生成:有兴趣的可以结合上一篇的进行实现:如有更 ...
- java_IO流
IO流概述及分类 Reader InputStream OutputStream Writer都是Object的直接子类 字节流: 字节输入流 InputStream(抽象类) |---File ...
- Windows有点腻了?不如试试Ubuntu.
最近在接触Python. 因为担心环境会向Java一样,很容易影响当前的工作电脑. 所以准备搭建一台虚拟机,不过Windows的尺寸是在太大了.所以,选择安装Ubuntu. Ubuntu官方网站地址: ...
- 小程序使用之WXS
文章链接:https://mp.weixin.qq.com/s/F1zzS7mvMpFaplq4KINzQg 之前做过一段时间的小程序开发,自己也写过两个自己的小程序,了解些前端的知识,相对而言还是比 ...
- 【English】八、食物相关
一.beer.wine.coffee.soup.oil.juice beer 啤酒 They drink beer. wine 葡萄酒 Wine and coffee. coffee 咖啡 Wine ...
- 开始食用grpc(之二)
开始食用grpc(之二) 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9570992.html ``` 前段时间有童鞋找我开专栏.搬家.甚至还有人找我写书的. ...
- Git - git status - 查看当前仓库状态
索引: 目录索引 参看代码 GitHub: git.txt 一.示例: git status 二.说明: 1."status" 部分 该命令可以查出当前分支文件变更状态, 可以查出 ...