全国站

热门城市 | 全国 北京 上海 广东

华北地区 | 北京 天津 河北 山西 内蒙古

东北地区 | 辽宁 吉林 黑龙江

华东地区 | 上海 江苏 浙江 安徽 福建 江西 山东

华中地区 | 河南 湖北 湖南

西南地区 | 重庆 四川 贵州 云南 西藏

西北地区 | 陕西 甘肃 青海 宁夏 新疆

华南地区 | 广东 广西 海南

资    源
  • 资    源
当前位置:查字典高考网>高中频道>信息学联赛知识>信息学联赛知识:Complete Search

信息学联赛知识:Complete Search

来自:查字典高考网 2009-11-12

Complete Search

The Idea

Solving a problem using complete search is based on the ``Keep It Simple, Stupid'' principle. The goal of solving contest problems is to write programs that work in the time allowed, whether or not there is a faster algorithm.

Complete search exploits the brute force, straight-forward, try-them-all method of finding the answer. This method should almost always be the first algorithm/solution you consider. If this works within time and space constraints, then do it: it's easy to code and usually easy to debug. This means you'll have more time to work on all the hard problems, where brute force doesn't work quickly enough.

In the case of a problem with only fewer than a couple million possibilities, iterate through each one of them, and see if the answer works.

Careful, Careful

Sometimes, it's not obvious that you use this methodology.

Problem: Party Lamps [IOI 98]

You are given N lamps and four switches. The first switch toggles all lamps, the second the even lamps, the third the odd lamps, and last switch toggles lamps 1, 4, 7, 10, ... .

Given the number of lamps, N, the number of button presses made (up to 10,000), and the state of some of the lamps (e.g., lamp 7 is off), output all the possible states the lamps could be in.

Naively, for each button press, you have to try 4 possibilities, for a total of 410000 (about 106020 ), which means there's no way you could do complete search (this particular algorithm would exploit recursion).

Noticing that the order of the button presses does not matter gets this number down to about 100004 (about 1016 ), still too big to completely search (but certainly closer by a factor of over 106000 ).

However, pressing a button twice is the same as pressing the button no times, so all you really have to check is pressing each button either 0 or 1 times. That's only 24 = 16 possibilities, surely a number of iterations solvable within the time limit.

Problem 3: The Clocks [IOI 94]

A group of nine clocks inhabits a 3 x 3 grid; each is set to 12:00, 3:00, 6:00, or 9:00. Your goal is to manipulate them all to read 12:00. Unfortunately, the only way you can manipulate the clocks is by one of nine different types of move, each one of which rotates a certain subset of the clocks 90 degrees clockwise.

Find the shortest sequence of moves which returns all the clocks to 12:00.

The ``obvious'' thing to do is a recursive solution, which checks to see if there is a solution of 1 move, 2 moves, etc. until it finds a solution. This would take 9k time, where k is the number of moves. Since k might be fairly large, this is not going to run with reasonable time constraints.

Note that the order of the moves does not matter. This reduces the time down to k9 , which isn't enough of an improvement.

However, since doing each move 4 times is the same as doing it no times, you know that no move will be done more than 3 times. Thus, there are only 49 possibilities, which is only 262,072, which, given the rule of thumb for run-time of more than 10,000,000 operations in a second, should work in time. The brute-force solution, given this insight, is perfectly adequate.

Sample Problems

Milking Cows [USACO 1996 Competition Round]

Given a cow milking schedule (Farmer A milks from time 300 to time 1000, Farmer B from 700 to 1200, etc.), calculate

The longest time interval in which at least one cow was being milked

The longest time interval in which no cow is being milked

Perfect Cows Perfect Cow Cousins [USACO 1995 Final Round]

A perfect number is one in which the sum of the proper divisors add up to the number. For example, 28 = 1 + 2 + 4 + 7 + 14. A perfect pair is a pair of numbers such that the sum of the proper divisor of each one adds up to the other. There are, of course, longer perfect sets, such that the sum of the divisors of the first add up to the second, the second's divisors to the third, etc., until the sum of the last's proper divisors add up to the first number.

Each cow in Farmer John's ranch is assigned a serial number. from 1 to 32000. A perfect cow is one which has a perfect number as its serial. A group of cows is a set of perfect cow cousins if their serial numbers form a perfect set. Find all perfect cows and perfect cow cousins.

retrieved from http://ace.delos.com/usacogate

【信息学联赛知识:Complete Search】相关文章:

高中数学联赛培训讲义(一)

“读、思、问”三者结合是攻克高中语文的最佳工具

高中数学竞赛基本知识集锦(三)

东城区明年推出新举措 示范高中推荐生名额增加一倍

九成人赞同高考改革 近六成人认为需要动大手术

全国高中数学联合竞赛简介

教育部:首批高中新课改省份高考实现平稳过渡

86所北京高校2007年具备高招资格

2007年全国高中数学联赛江西省预赛试卷

课改与高考脱节 素质教育校园很难真正践行

[标签:竞赛联赛,数学联赛]

网友关注

教育部:创新培养纳入本科教学质量国家标准

大学教授给大学新生的22条忠告

警惕高考考生信息泄露被用于招生诈骗

为上百名高考移民开绿灯 教委副主任获刑

时评:军训都轻轻松松还算什么军训?

习近平:推动一批大学和学科跻身世界一流

2015届获国家助学贷款大学生 可申创业补贴

盘点全国高校住宿条件最好的十所大学

从九大方面解读美国高中与中国高中的区别

女生高考完便去打工 上大学不准备买新衣服

高考扶贫为寒门学子进入名校增添敲门砖

高考命题缘何“合久必分,分久必合”

双胞胎姐妹同上清华:课本是根本 不需要补课

小伙高考失利跳水轻生 警察开导:明年还可努力

替考行业背后:谁来谴责枪手的“买家”

大学文凭有用吗:美调查称高学位有助求职

高中开设生涯规划课程 学生提前体验职场

高等学校学生资助政策简介(2015)(本专科学生)

农村生进名校与城市生差距大:不知PPT是啥

高校新生入学 至少三类奖学金等你拿

清华与江西招生闹剧升级:高分考生称被迫上北大

教育部:取消少数民族高考加分还没有时间表

一场“真人秀”里的教育碰撞

学校招生引发冲突 两女生受轻微伤

迈入大学门 做好“心”准备

2015高考录取接近尾声:部分高职录取线赶超二本

高考志愿先选学校还是先选专业?正确结论居然是。。。

10万高考生信息泄露 多省招办:砸钱读本科不靠谱

高考扶贫,上马还需扶一程(图)

外媒称中国高考是把双刃剑:希望与痛苦并存

网友关注视频

招办面对面 第2集 中国科学技术大学

爆笑班主任 第一季 第221集 高考结束学生有多疯狂?山东王老师疯狂吐槽

这四首励志歌曲,送给为梦起航的高考学子们,听完心潮澎湃!

这!就是专业 第36集 河北经贸大学——数学专业

探秘历史 第二季 第233集 考英语用来睡觉,结果仍是高考状元,如今她怎么样了?

这!就是专业 第20集 长沙理工大学—数据科学专业

武汉美术高考

张雪峰高考志愿填报指南 第15集 高考填报志愿,想学电子信息类专业,推荐报这六所高校,不出错

老马讲高考真题第九季2018年高考地理新课标一卷第37题

高考政治一轮:《经济生活》第九课(社会主义市场经济)练习

最新高考数学全国2第12题视频讲解及答案

amc传媒音乐影像 第一季 第598集 西安原创乐队走进英泰青卓 用音乐助力高考学子

男孩考上理想大学,却因为网瘾休学在家,高中班主任上门劝导

体育生参加高考,太猛了,第一名是飞起来了吗?

外国数学老师挑战中国高考题,一顿“凶猛操作”下来,被虐惨!

乾坤已定,组合解读2019高考数学全国3卷理科18题,你是黑马吗?

老师好:这大概是高考前所有班主任都会干的事,取消一切副课!

学渣儿子高考,英语选择题全选B!老师通报成绩的那一刻父亲懵了

高考阅卷名师给考生的高考作文密训课 第4集 高考作文审题实操方法精讲(二)

1000张学生用草稿纸考研专用免邮空白便宜薄演草演算纸白纸本书写纸批发打草a4大张实惠装18k高考数学草稿本

2019高考·语文试题有亮点 凸显时代主题 厚植家国情怀

初二辍学,3次高考落榜,如今却成为最成功的音乐人之一

视频|2019全国高考今日开考: 语文特级教师评析上海卷高考作文

高考英语作文分析2

2019高考语文试卷解析

张雪峰高考志愿填报指南 第28集 高考志愿分析,材料科学与工程专业,就业很一般,建议慎重选择

凤凰县高级中学高考试卷分析专题教研会

良心推荐:2019高考数学全国3卷理科12题讲解,附答案

【姜浩张超画室】

这!就是专业 第31集 阜阳师范学院信息工程学院