纪中17日T1 2321. 方程

(File IO): input:cti.in output:cti.out

时间限制: 1000 ms  空间限制: 262144 KB  具体限制  

Goto ProblemSet

题目描述

输入

输出

样例输入

样例输出

数据范围限制

提示

吐槽

这些图片太模糊了吧……

还有那吓人的 mod 998244353

都使得我们对这道题的恐惧感叠加了998244353层……

没想到……只有三种答案!(三进制呵呵哒)

Solution

(约定:用line[i]表示第i个输入的数据,man[i]表示在第i位是否为男生(i from 1 to n))

step1

先对line[1]进行判断:

  若line[1]==0

    直接dfs

  若line[1]==1

    进行两遍dfs,其中一遍man[1]=1,另一边man[2]=1;

  若line[1]==2

    一遍dfs,man[1]=man[2]=1;

if(line[]==){
man[]=;
dfs();
memset(man,,sizeof(man));
man[]=;
dfs();
}
if(line[]==) dfs();
if(line[]==){
man[]=man[]=;
dfs();
}

处理完在边缘位置的line[1]后,接下来就好操作了。

step2

写dfs

int t,n,ans,line[];
bool man[];
IL void dfs(int depth)
{
int now=;
if(depth>) now+=man[depth-];
if(depth<n) now+=man[depth+];
now+=man[depth];
if(now!=line[depth]) return;
if(depth==n){
ans++;
return;
}
man[depth+]=;
dfs(depth+);
man[depth+]=;
dfs(depth+);
}

step3

按照题目的意思

怎么看上去像打了马赛克呢……

这个快读是专门给line的!

IL int read()
{
char ch=getchar();
while(ch<''||ch>'')
{
ch=getchar();
}
return (int)ch^;
}
for(int i=;i<=n;i++)
line[i]=read();

step4

输出答案

printf("%d\n",ans/);

别问我为什么要除以2

自己去推到dfs的结果吧。

我已经被接下来的问题折磨疯了……

Code

#include<iostream>
#include<cstdio>
#include<cstring>
#define IL inline
using namespace std;
int t,n,ans,line[];
bool man[];
IL void dfs(int depth)
{
int now=;
if(depth>) now+=man[depth-];
if(depth<n) now+=man[depth+];
now+=man[depth];
if(now!=line[depth]) return;
if(depth==n){
ans++;
return;
}
man[depth+]=;
dfs(depth+);
man[depth+]=;
dfs(depth+);
}
IL int read()
{
char ch=getchar();
while(ch<''||ch>'')
{
ch=getchar();
}
return (int)ch^;
}
int main()
{
// freopen("cti.in","r",stdin);
// freopen("cti.out","w",stdout);
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ans=;
memset(man,,sizeof(man));
for(int i=;i<=n;i++)
line[i]=read();
if(line[]==){
man[]=;
dfs();
memset(man,,sizeof(man));
man[]=;
dfs();
}
if(line[]==) dfs();
if(line[]==){
man[]=man[]=;
dfs();
}
printf("%d\n",ans/);
}
return ;
}

Problem

我不能通过#9!

运行时错误?

我又调试了很久很久……

发现了一个叫“段错误”的东西

program received signal SIGSEGV,segmentation fault

有些内存是内核占用的或者是其他程序正在使用,为了保证系统正常工作,所以会受到系统的保护,而不能任意访问。

或者时数组越界……

老师正在看另一个老师打游戏,不想理我……

哼唧……

纪中17日T1 2321. 方程的更多相关文章

  1. 纪中10日T1 2313. 动态仙人掌

    纪中10日 2313. 动态仙人掌 (File IO): input:dinosaur.in output:dinosaur.out 时间限制: 1500 ms  空间限制: 524288 KB  具 ...

  2. 纪中5日T1 1564. 旅游

    1564. 旅游 题目描述 输入N个数,从中选择一些出来计算出总和,问有多少种选法使得和为质数. 输入 第一行一个整数N. 第二行N个整数,表示这N个数的值. 输出 一个整数,表示方案数. 样例输入 ...

  3. 纪中12日T1 2307. 选择

    2307. 选择 (File IO): input:choose.in output:choose.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Pr ...

  4. 纪中17日T2 2322. capacitor

    2322. capacitor (File IO): input:capacitor.in output:capacitor.out 题目描述 输入 输出 样例输入 样例输出 数据范围限制 Solut ...

  5. 纪中10日T1 2300. 【noip普及组第一题】模板题

    2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms  空间限制: 262144 K ...

  6. 纪中21日T3 2118. 【2016-12-30普及组模拟】最大公约数

    纪中21日T3 2118. 最大公约数 (File IO): input:gcd.in output:gcd.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制 Goto ...

  7. 纪中23日c组T2 2159. 【2017.7.11普及】max 洛谷P1249 最大乘积

    纪中2159. max 洛谷P1249 最大乘积 说明:这两题基本完全相同,故放在一起写题解 纪中2159. max (File IO): input:max.in output:max.out 时间 ...

  8. 纪中23日c组T3 2161. 【2017.7.11普及】围攻 斐波那契数列

    2161. 围攻 (File IO): input:siege.in output:siege.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Prob ...

  9. 洛谷P1880 [NOI1995]石子合并 纪中21日c组T4 2119. 【2016-12-30普及组模拟】环状石子归并

    洛谷P1880 石子合并 纪中2119. 环状石子归并 洛谷传送门 题目描述1 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石 ...

随机推荐

  1. 使用nginx搭建一个可用的静态资源web服务器

    新建dlib目录,dlib里面放着很多index.html文件 修改conf文件 配置location,/所有的请求,这里一般使用alias,这样url后面的路径和dlib/下面的路径是一一对应的,如 ...

  2. FFMPEG学习----使用SDL构建音频播放器

    ffmpeg版本:ffmpeg-20160413-git-0efafc5 #include <stdio.h> #include <stdlib.h> #include < ...

  3. LaTeX技巧472:定义一个LaTeX参考文献不带编号且有缩进的方法

    LaTeX_Fun的博客 LaTeX技巧381:参考文献项第二行缩进如何定义? \makeatletter\renewenvironment{thebibliography}[1]{\section* ...

  4. POJ_2479_DP

    http://poj.org/problem?id=2479 从前向后保存起点到每一点的最长串,从后向前保存尾点到每一点的最长串. 然后枚举中断点,找前后和最大值就行了. #include<io ...

  5. 5G为人工智能与工业互联网赋能 高清79页PPT

    人工智能和5G是时下最热门的科技领域之一,两者都是能改变社会,推进下一代工业革命的颠覆性技术. 工业互联网是利用基础科学.工业.信息技术.互联网等领域的综合优势,从大数据应用等软服务切入,注重软件.网 ...

  6. 《java多线程编程核心技术》不使用等待通知机制 实现线程间通信的 疑问分析

    不使用等待通知机制 实现线程间通信的 疑问分析 2018年04月03日 17:15:08       ayf 阅读数:33 编辑 <java多线程编程核心技术>一书第三章开头,有如下案例: ...

  7. Go语言实现:【剑指offer】数字在排序数组中出现的次数

    该题目来源于牛客网<剑指offer>专题. 统计一个数字在排序数组中出现的次数. 看到排序数组,要想到用二分查找. 先找到最前面的数字k,再找到最后面的数字k,通过下标求出次数. Go语言 ...

  8. javascript A*算法 寻路算法 获取最短路径算法

    //A算法 自动寻路 路径 class GetAutoPath{ constructor(id, map, sPos, ePos, mapArr){ //this.type = id.type; th ...

  9. 杭电-------2098 分拆素数和(c语言写)

    #include<stdio.h> #include<math.h> ] = { , }; ;//全局变量,用来标志此时已有多少个素数 int judge(int n) {// ...

  10. python2 + Django 中文传到模板页面变Unicode乱码问题

    1.确保views页面首行设置了默认编码   # -*-coding:utf-8 -*- 2.确保html页面的编码为 utf-8 3.确保项目setting文件设置了 LANGUAGE_CODE = ...