https://www.zybuluo.com/ysner/note/1243396

题面

有\(n\)个排成一圈的格子,并且已知正整数\(k\)和\(m\),你需要往每个格子中填入一个大于等于\(k\)的正整数。将相邻的一些格子(或一个单独的格子)中的数加起来,可以产生一个新的数。假设使用格子中的数可以产生出\(m,m+1,…i\),但不能产生\(i+1\)。求出往格子中填入哪些数,可以使得\(i\)尽量大。

对于同一个环,输出字典序最小的方案。

  • \(30pts\ n\leq5\)
  • \(100pts\ n\leq6,m,k\leq20\)

解析

看这部分分分布就知道是暴搜+剪枝。

\(30pts\)算法

卡着复杂度枚举每个数,再枚举两端点找出产生的所有数即可。(好像是\(k~k+18\))

至于怎么去重,我傻逼地打了哈希,只能过样例。

实际上保证后面每位数不比第一位小就可以了啊。

\(100pts\)算法

可以打表发现,填入的数最大为\(k+15\)。

于是继续暴枚就能过了。

复杂度\(O(16^6n^2)=O(6*10^8)\),然而由于前面枚举的限制,复杂度不满(除以\(6\))。

附上题解剪枝:

假设当前已经确定前\(k\)个格子中的数。将前\(k\)个格子不能产生的大于等于\(m\)的数从小到大排序,设为\(a_1,a_2,...\)。假设由后面\(n-k\)个格子最多可以再产生\(x\)个数,则第\(k+1\)个数不能超过 \(a[x]\)。

加上这个剪枝似乎快\(3\)倍,然而懒得打。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define re register
#define il inline
#define ll long long
#define q 15
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define fp(i,a,b) for(re int i=a;i<=b;i++)
#define fq(i,a,b) for(re int i=a;i>=b;i--)
using namespace std;
const int mod=1e9+7,N=20,M=1e5+100;
int n,m,k,a[N],ans[M][N],tot,p[N],tong[M],anss,top;
ll jc[70];
map<ll,bool>vis;
il ll gi()
{
re ll x=0,t=1;
re char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') t=-1,ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*t;
}
il int check()
{
fp(i,n+1,n+n) a[i]=a[i-n];
fp(i,1,n+n) p[i]=p[i-1]+a[i];
fp(i,1,p[n+n]) tong[i]=0;
fp(l,1,n)
fp(r,l,l+n-1)
tong[p[r]-p[l-1]]=1;
re int x=m;
while(tong[x]) ++x;--x;
if(x>anss) {anss=x;tot=0;return 1;}
return (x==anss);
}
int main()
{
freopen("circle.in","r",stdin);
freopen("circle.out","w",stdout);
jc[0]=1;fp(i,1,60) jc[i]=jc[i-1]*2;
n=gi();m=gi();k=gi();
if(n==5)
for(a[1]=k;a[1]<=k+q;a[1]++)
for(a[2]=a[1];a[2]<=k+q;a[2]++)
for(a[3]=a[1];a[3]<=k+q;a[3]++)
for(a[4]=a[1];a[4]<=k+q;a[4]++)
for(a[5]=a[1];a[5]<=k+q;a[5]++)
if(check()) ans[++tot][1]=a[1],ans[tot][2]=a[2],ans[tot][3]=a[3],ans[tot][4]=a[4],ans[tot][5]=a[5];
if(n==6)
for(a[1]=k;a[1]<=k+q;a[1]++)
for(a[2]=a[1];a[2]<=k+q;a[2]++)
for(a[3]=a[1];a[3]<=k+q;a[3]++)
for(a[4]=a[1];a[4]<=k+q;a[4]++)
for(a[5]=a[1];a[5]<=k+q;a[5]++)
for(a[6]=a[1];a[6]<=k+q;a[6]++)
if(check()) ans[++tot][1]=a[1],ans[tot][2]=a[2],ans[tot][3]=a[3],ans[tot][4]=a[4],ans[tot][5]=a[5],ans[tot][6]=a[6];
printf("%d\n",anss);
fp(i,1,tot)
{
fp(j,1,n) printf("%d ",ans[i][j]);puts("");
}
fclose(stdin);
fclose(stdout);
return 0;
}

[bzoj3274]Circle的更多相关文章

  1. [翻译svg教程]svg中的circle元素

    svg中的<circle> 元素,是用来绘制圆形的,例如 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink= ...

  2. 设计一个程序,程序中有三个类,Triangle,Lader,Circle。

    //此程序写出三个类,triangle,lader,circle:其中triangle类具有类型为double的a,b,c边以及周长,面积属性, //具有周长,面积以及修改三边的功能,还有判断能否构成 ...

  3. c++作业:Circle

    Circle Github链接

  4. Modified Least Square Method and Ransan Method to Fit Circle from Data

    In OpenCv, it only provide the function fitEllipse to fit Ellipse, but doesn't provide function to f ...

  5. [javascript svg fill stroke stroke-width circle 属性讲解] svg fill stroke stroke-width circle 属性 绘制圆形及引入方式讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  6. (1)编写一个接口ShapePara,要求: 接口中的方法: int getArea():获得图形的面积。int getCircumference():获得图形的周长 (2)编写一个圆类Circle,要求:圆类Circle实现接口ShapePara。 该类包含有成员变量: radius:public 修饰的double类型radius,表示圆的半径。 x:private修饰的double型变量x,

    package com.hanqi.test; //创建接口 public interface ShapePara { //获取面积的方法 double getArea(); //获取周长的方法 do ...

  7. 东大oj-1591 Circle of friends

    题目描述 Nowadays, "Circle of Friends" is a very popular social networking platform in WeChat. ...

  8. svg学习(四)circle

    <circle> 标签 < <?xml version="1.0" standalone="no"?> <!DOCTYPE ...

  9. 后缀数组 --- WOj 1564 Problem 1564 - A - Circle

    Problem 1564 - A - Circle Problem's Link:   http://acm.whu.edu.cn/land/problem/detail?problem_id=156 ...

随机推荐

  1. 配置redis三主三从

    主从环境 centos7.6 redis4.0.1 主 从 192.168.181.139:6379 192.168.181.136:6379 192.168.181.136:6380 192.168 ...

  2. error: Bean property 'userDAO' is not writable or has an invalid setter method.

    使用Spring属性注入的方式,没有在ServiceImpl中setDao,导致程序报错 public class AddressServiceImpl implements IAddressServ ...

  3. printf函数压栈(i++/i--,++i/--i) 终极解密

    #include <stdio.h> void main() { ; printf("%d %d %d %d\n", i, --i, i, i--); } 输出是“3 ...

  4. 安装charles

    简介: Charles主要的功能包括: 支持SSL代理.可以截取分析SSL的请求. 支持流量控制.可以模拟慢速网络以及等待时间(latency)较长的请求. 支持AJAX调试.可以自动将json或xm ...

  5. 用python写了一个猜年龄小游戏

    写一个猜年龄游戏: 需要实现用户登录的功能 初始用户登录信息为 {'hades': '13579','nick': '123','ruixing': 'a1','fanping': 'b2'} 登录时 ...

  6. Python基础函数

    join()函数的用法 join()函数连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 语法:'sep'.join(seq) 参数说明sep:分隔符.可以为空 ...

  7. js之循环语句

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Wind rotor states

    test test Table of Contents 1. Wind rotor states 1.1. Turbulent Wake State 1.2. Vortex Ring State 1. ...

  9. IOC控制反转之Autofac

    https://www.jianshu.com/p/1b6cb076e2e5 博主:衡泽_徐峰 Autofac官网:https://autofac.org/ Autofac 是.Net非常好的一个IO ...

  10. redis学习-简介

    1. Redis 简介 1.1 Redis是什么 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Red ...