https://zoj.pintia.cn/contests/91827364639/problems

C

要把这两个二进制串变为相同,需要先看哪些位置不同,设为数组c,某位为1则两位不同。

分1形成两段、四段或者更多段来考虑。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define ld double
#define lson rt << 1, l, m
#define pi acos(-1)
#define rson rt << 1 | 1, m + 1, r
#define fo(i, l, r) for (long long i = l; i <= r; i++)
#define fd(i, l, r) for (long long i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 1e-10
using namespace std;
const ll maxn = ;
const ll mod = ;
ll read()
{
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= ''))
{
if (ch == '-')
f = -;
ch = getchar();
};
while (ch >= '' && ch <= '')
{
x = x * + (ch - '');
ch = getchar();
};
return x * f;
}
int n,m;
char s[maxn],t[maxn];
int pt[];
ll ans;
int main()
{ int T;
T = read();
int tt = ;
while (T--)
{
ans=;
n=read();
scanf("%s",s+);
scanf("%s",t+);
fo(i,,n){
s[i]-='';
t[i]-='';
s[i] ^= t[i];
}
int cnt = ;
fo(i,,n){
if(s[i]&&!s[i-]){
pt[++cnt]=i;
}
if(s[i]&&!s[i+]){
pt[++cnt]=i;
}
if(cnt>)break;
}
if(cnt>){
printf("0\n");
continue;
}
if(cnt==){
ans=(ll)n*(n+)/;
}
if(cnt==){
ans=n+n-;
}
if(cnt==){
ans=;
}
printf("%d\n",ans); } return ;
}

M

递归,碰到循环节就停止。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define ld double
#define lson rt << 1, l, m
#define pi acos(-1)
#define rson rt << 1 | 1, m + 1, r
#define fo(i, l, r) for (long long i = l; i <= r; i++)
#define fd(i, l, r) for (long long i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 1e-10
using namespace std;
const ll maxn = ;
const ll mod = ;
ll read()
{
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= ''))
{
if (ch == '-')
f = -;
ch = getchar();
};
while (ch >= '' && ch <= '')
{
x = x * + (ch - '');
ch = getchar();
};
return x * f;
}
ll x,k;
ll f[] = {,,,,,,,,,};
ll g(int d,ll x){
if(d==) return x;
if(x==||x==){
return x^(d&);
}
ll ret = ;
while(x){
ret += f[x%];
x /= ;
}
return g(d-,ret);
}
int main()
{ int T;
T = read();
int tt = ;
while (T--)
{
x=read();k=read();
printf("%lld\n",g(k,x));
}
return ;
}

J

正好买m本书,还要带的钱最多。

考虑到,如果跳过若干本书,买一本,那把后一本书换成一开始跳过的书,答案会增加。

即,不存在这样的情况,买的书肯定是从1开始到m。

这个时候答案依然可能增加,要保证之后买不了书,就是加上之后价格最小的那本书-1

再判断一些特殊情况就可以。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define ld double
#define lson rt << 1, l, m
#define pi acos(-1)
#define rson rt << 1 | 1, m + 1, r
#define fo(i, l, r) for (long long i = l; i <= r; i++)
#define fd(i, l, r) for (long long i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 1e-10
using namespace std;
const ll maxn = ;
const ll mod = ;
ll read()
{
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= ''))
{
if (ch == '-')
f = -;
ch = getchar();
};
while (ch >= '' && ch <= '')
{
x = x * + (ch - '');
ch = getchar();
};
return x * f;
}
int n,m;
ll a[maxn],ans;
int main()
{ int T;
T = read();
int tt = ;
while (T--)
{
ans=;
n=read();m=read();
fo(i,,n){
a[i]=read();
if(!a[i]){
i--;
n--;
m--;
}
}
if(m<||m>n){
printf("Impossible\n");
continue;
}
if(m==n){
printf("Richman\n");
continue;
}
fo(i,,m){
ans += a[i];
}
ll mn = 1e10;
fo(i,m+,n){
mn = min(mn,a[i]);
}
mn--;
ans+=mn;
printf("%lld\n",ans);
} return ;
}

E

试着将操作进行分解,前进n次,倒退n次,把这些操作全部换成前进1次,倒退1次的操作,答案不会变劣。

首先二分,检验的时候,不断往前走,如果某个时刻发现前一个点不能满足要求,就在这两个点之间反复的跳,注意考虑最后一个点的情况。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define ld double
#define lson rt << 1, l, m
#define pi acos(-1)
#define rson rt << 1 | 1, m + 1, r
#define fo(i, l, r) for (long long i = l; i <= r; i++)
#define fd(i, l, r) for (long long i = r; i >= l; i--)
#define mem(x) memset(x, 0, sizeof(x))
#define eps 1e-10
using namespace std;
const ll maxn = ;
const ll mod = ;
ll read()
{
ll x = , f = ;
char ch = getchar();
while (!(ch >= '' && ch <= ''))
{
if (ch == '-')
f = -;
ch = getchar();
};
while (ch >= '' && ch <= '')
{
x = x * + (ch - '');
ch = getchar();
};
return x * f;
}
ll a[maxn],b[maxn],c[maxn];
ll n,m,mx;
bool check(ll t){
int nown = n;
fo(i,,n){
b[i]=t/a[i];
if(b[i]*a[i]<t)b[i]++;
}
b[n+]=;
while(nown>=&&b[nown]==)nown--;
fo(i,,nown+){
if(i<=n)c[i]=;
else c[i]=;
if(b[i-]>c[i-]){
c[i] += b[i-]-c[i-];
c[i-]=b[i-];
}
if(i==n&&c[i]>b[i])c[i]--; }
ll ret = ;
fo(i,,nown+){
ret += c[i];
if(ret > m) return false;
}
return true;
}
int main()
{ int T;
T = read();
int tt = ;
while (T--)
{
n=read();m=read();
mx=;
fo(i,,n){
a[i]=read();
mx=max(mx,a[i]);
}
ll lp = ,rp = mx*m,mid,ans=;
while(lp<=rp){
mid = (lp + rp) >> ;
if(check(mid)){
ans = mid;
lp = mid + ;
}else{
rp = mid - ;
}
}
printf("%lld\n",ans);
} return ;
}

F

首先,n个人最多打n-1轮,奇数个人不能打。

2、4个人都能打,然后发现6个人连两轮都打不了。

一开始是 2 1 4 3 6 5,假如说之后1个3打,按照只能要求1 2 3 4之间有比赛,5还是只能跟6打,因为第二轮与人的序号无关,这时候怎么调整都是徒劳。

人数是2^n的时候比较好安排,轮换一下就可以。

人数不是2^n的时候,还是按照2^n的情况排个表,因为之前就是保证字典序最小,所以编号大的都尽量出现在后面,如果这个时候表中出现了不得不跟一个不存在的大号打的情况,这个时候就安排不了了。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include <set>
#include <queue>
#define ll long long
#define ld long double
#define lson l,m,rt<<1
#define pi acos(-1)
#define rson m+1,r,rt<<1|1
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
#define mem(x) memset(x,0,sizeof(x))
#define eps 3e-11
using namespace std;
const int maxn = ;
const ll inf = 1e9;
const ll mod = ;
ll read() {
ll x=,f=;
char ch=getchar();
while(!(ch>=''&&ch<='')) {
if(ch=='-')f=-;
ch=getchar();
};
while(ch>=''&&ch<='') {
x=x*+(ch-'');
ch=getchar();
};
return x*f;
}
int n,k;
int a[][];
int main() {
a[][]=a[][]=;
a[][]=a[][]=;
for(int t = ;t <= ;t <<= ){
fo(i,,t){
fo(j,,t){
a[t+i][t+j] = a[i][j];
a[t+i][j] = a[i][t+j] = a[i][j] + t;
}
}
}
int T=read();
while(T--){
n=read();k=read();
if((n&)||k>=n){
puts("Impossible");
continue;
}
bool flag = false;
fo(i,,k){
fo(j,,n){
if(a[i+][j] > n)flag=true;
}
}
if(flag){
puts("Impossible");
continue;
}
fo(i,,k){
fo(j,,n){
printf("%d",a[i+][j]);
putchar(j==n?'\n':' ');
}
}
}
return ;
}

D

枚举两个数的第一位,之后所有的位都确定了。

注意两位数不能有前导零,每一位的范围不能超。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include <set>
#include <queue>
#define ll long long
#define ld long double
#define lson l,m,rt<<1
#define pi acos(-1)
#define rson m+1,r,rt<<1|1
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
#define mem(x) memset(x,0,sizeof(x))
#define eps 3e-11
using namespace std;
const int maxn = ;
const ll inf = 1e9;
const ll mod = ;
ll read() {
ll x=,f=;
char ch=getchar();
while(!(ch>=''&&ch<='')) {
if(ch=='-')f=-;
ch=getchar();
};
while(ch>=''&&ch<='') {
x=x*+(ch-'');
ch=getchar();
};
return x*f;
}
ll n,m,len;
char s[maxn];
int a[maxn],b[maxn];
bool flag;
inline int check(int u,int v,int t){
if(a[u]*b[v]==s[t])return ;
if(t<len&&s[t]&&(s[t]*+s[t+])==a[u]*b[v]) return ;
return ;
}
inline int dv(int v,int t){
if(s[t]%v==) return s[t]/v;
if(t<len&&(s[t]*+s[t+])%v==) return (s[t]*+s[t+])/v;
return -;
}
bool check(int st){
int t = st,u=,v=,sgn;
while(t<=len){
v++;
if(v>m){
v=;
u++;
}
if(u>n)break;
if(u==){
b[v]=dv(a[u],t);
if(b[v]==-||b[v]>=)return false;
}else if(v==){
a[u] = dv(b[v],t);
if(a[u]==-||a[u]>=)return false;
}else{
sgn=check(u,v,t);
if(!sgn)return false;
}
t++;
if(a[u]*b[v]>=)t++;
}
return u==n&&v==m&&t==len+;
}
bool gao(){
int sgn;
fo(i,,){
fo(j,,){
a[]=i;b[]=j;
sgn=check(,,);
if(!sgn)continue;
if(check(sgn+))return true;
}
}
return false;
}
int main() {
int T=read();
while(T--){
flag=false;
n=read();m=read();
scanf("%s",s+);
len = strlen(s+);
if(n*m>len||n*m*<len){
puts("Impossible");
continue;
}
fo(i,,len) s[i]-='';
if(gao()){
fo(i,,n){
putchar(''+a[i]);
}
putchar(' ');
fo(i,,m){
putchar(''+b[i]);
}
putchar('\n');
}else{
puts("Impossible");
}
}
return ;
}

2018 icpc 青岛的更多相关文章

  1. 2018 icpc 青岛网络赛 J.Press the Button

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

  2. 2018 ICPC青岛网络赛 B. Red Black Tree(倍增lca好题)

    BaoBao has just found a rooted tree with n vertices and (n-1) weighted edges in his backyard. Among ...

  3. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  4. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  5. 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

    题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...

  6. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  7. 2016 ICPC青岛站---k题 Finding Hotels(K-D树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...

  8. 2018.9青岛网络预选赛(B)

    传送门:Problem(B) https://www.cnblogs.com/violet-acmer/p/9664805.html 参考资料: https://blog.csdn.net/qq_40 ...

  9. 2018.9青岛网络预选赛(K)

    传送门:Problem K https://www.cnblogs.com/violet-acmer/p/9664805.html 题意: 给你n个数,找出满足条件的最多的数的个数. 题解: 满足条件 ...

随机推荐

  1. 20180115-Xcode创建多个工程协同开发

    今天研究了一下在Xcode中创建多个工程,达到模块化的目的的同时,实现多个相似项目的协同开发,最主要的是可以实现多工程连编.项目的效果如下: 接下来创建一个这样的项目,以及他们之间的通信 1.建一个文 ...

  2. Python操作Redis,你要的都在这了!

    Redis是一个基于内存的高效的键值型非关系型数据库,存取效率极高,而且支持多种存储数据结构,使用也非常简单.本节中,我们就来介绍一下Python的Redis操作,主要介绍RedisPy这个库的用法. ...

  3. PHP5 构造函数

    在最近自己写的PHP小程序中遇到了如何使用PHP构造函数的情况,在PHP中允许我们在一个类中定义一个构造函数 如: <?php class User { public $name; functi ...

  4. docker常用技巧

    1:运行中容器如何保存为一个镜像? docker commit 容器名字 镜像名字 2:怎么给容器增加名字 docker rename 容器id(或名字)name(新名字) 3:docker中的Doc ...

  5. win 与Linux 的hosts文件地址

    win(phpstudy):C:/Windows/System32/drivers/etc/hosts linux:  /etc/hosts

  6. ifconfig命令返回找不到“-bash: ifconfig: command not found”

    “-bash: ifconfig: command not found“因为系统没有安装net-tools yum -y install net-tools

  7. SpringBoot之持久化框架

    在之前的 Spring学习之旅(十二)--持久化框架 中我们介绍了 JPA 的使用,今天我们就来了解下另一种持久化框架 Mybatis. 一.集成 Mybatis 1.1 准备工作 新建用户表 CRE ...

  8. SpringMVC @PathVariable注解

    下面用代码来演示@PathVariable传参方式 @RequestMapping("/user/{id}") public String test(@PathVariable(& ...

  9. java集合源码分析几篇文章

    java集合源码解析https://blog.csdn.net/ns_code/article/category/2362915

  10. 014:Django内置的URL转换器

    Django内置的URL转换器: 上节中我们说了URL中传参的情况,传递参数是通过 <> 尖括号来进行指定的.并且在传递参数的时候,可以指定这个参数的数据类型,比如文章的 id 都是 in ...