题意:n个点,给定起点和终点,可以每次可以走一格或两格,走一格则需要一个代价,每个格子只能走一次,问从起点到终点并经过每一个点的最小代价

思路:这题我没看出什么道理,先打了个暴力,结果发现了个相当坑的规律,,然后就过了。

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 200005
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int n, s, t, o;
while(~scanf("%d%d%d", &n, &s, &t)){
//printf("%d %d %d %d ", n, s, t, o);
int ans;
if(s == t){
ans = ;
}
else{
if(s > t){
swap(s, t);
}
if(t - s == ){
if(s != && t != n){
ans = -;
}
else{
ans = ;
}
}
else{
int tt = n -s + ;
int ss = n - t + ;
if(ss < s){
s = ss;
t = tt;
}
int p;
if(s == ){
p = t - s - ;
ans = + p / + (p % );
}
else{
p = t - s - ;
ans = + p / + (p % );
}
}
}
if(s == && t == n && n % == ){
ans -= ;
}
printf("%d\n", ans);
}
/*while(~scanf("%d%d%d", &n, &s, &t)){
memset(vis, 0, sizeof(vis));
vis[s] = true;
vis[t] = true;
ans = INF;
dfs(s, 0, 0);
if(ans == INF){
printf("%d %d %d -1\n", n, s, t);
continue;
}
printf("%d %d %d %d\n", n, s, t, ans);
}*/
}

下面是暴力的

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 200005
int n, s, t;
int ans;
bool vis[MAXN];
using namespace std;
void dfs(int x, int cnt, int cost){
if(cnt == n - ){
if(abs(x - t) == ){
ans = min(ans, cost + );
}
else if(abs(x - t) == ){
ans = min(ans, cost);
}
else{
return;
}
}
int y;
for(int i = ; i <= ; i++){
int p = i == ? : ;
y = x + i;
if(y >= && y <= n && !vis[y]){
vis[y] = true;
dfs(y, cnt + , cost + p);
vis[y] = false;
}
y = x - i;
if(y >= && y <= n && !vis[y]){
vis[y] = true;
dfs(y, cnt + , cost + p);
vis[y] = false;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE while(~scanf("%d%d%d", &n, &s, &t)){
memset(vis, , sizeof(vis));
vis[s] = true;
vis[t] = true;
ans = INF;
dfs(s, , );
if(ans == INF){
printf("-1\n");
return ;
}
printf("%d\n", ans);
}
}

Gym - 100637B Lunch 规律的更多相关文章

  1. CF Gym 100637B Lunch(拆分子问题)

    题意:在一条狭窄的沼泽上有一列数量为n的连续荷叶,编号为1-n.有一只蛤,在边s号荷叶上,其他荷叶上苍蝇,哈可以跳到相邻的荷叶上,或者越过一片荷叶,跳完以后原来的荷叶会沉,目标是f荷叶,在跳到f荷叶之 ...

  2. Codeforces Gym 100637B B. Lunch 找规律

    B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Des ...

  3. Gym - 101911C Bacteria (规律题)

    传送门:点我 Time limit2000 ms Memory limit262144 kB Recently Monocarp has created his own mini-laboratory ...

  4. Gym 101334J 找规律

    题意: 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + - + k mod n的值,其中k mod i表示k除以i的余数.例如j(5, 3)=3 mo ...

  5. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  6. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  7. Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]

    题目链接:http://codeforces.com/gym/101981/attachments The use of the triangle in the New Age practices s ...

  8. Codeforces Gym 100015B Ball Painting 找规律

    Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...

  9. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

随机推荐

  1. mysql日期加减运算

    MySQL 日期类型MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型        存储空间       日期格式                 日期范围 --------- ...

  2. c 和 指针读书笔记(1)

    1.字符串常量:出现在表达式中,其值是一个指针 "abc" + 1; //b 2.回掉函数:就是把函数的作为参数传入父函数,函数本身就是一个地址,传址肯定没问题.至于父函数是想用函 ...

  3. Solr全文检索引擎配置及使用方法

    介绍 Solr是一款开源的全文检索引擎,基于lucene.拥有完善的可配置功能界面.具有丰富的查询语言,可扩展,可优化. 下载安装 进入solr官网下载包(这里我使用的版本是8.0) http://w ...

  4. PostGIS解析Geometry几何对象

    一.Geometry转WKT select st_astext(geom) where tableName; 二.PostGIS常用函数 wkt转geometry st_geomfromtext(wk ...

  5. 北京联通光猫WO-36(HG220GS-U)改为桥接模式

    家里弄了个极路由,想在公司里去操作路由器,交换文件.提前下载电影什么的,因此需要光猫改为桥接模式,让路由器拨号 由于WO-36(HG220GS-U)这个型号的光猫固件升级后(我的是3.x)不能用工程账 ...

  6. CodeForces 453A

    Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she ...

  7. NGUI研究之开发项目的一些使用心得比較细节

     不知不觉使用NGI插件已经有一段时间了.感觉NGUI真的是眼下Unity3D中最好用的UI插件. 可是它也有一些不是BUG的BUG,这些问题可能会让新人摸不着头脑,那么这篇文章将总结一下这段时间 ...

  8. JavaScript加密解密7种方法

    注:本文纯转贴,供学习使用 本文一共介绍了七种javascript加密方法: 在做网页时(其实是网页木马呵呵),最让人烦恼的是自己辛辛苦苦写出来的客户端IE运行的javascript代码常常被别人轻易 ...

  9. angularjs 标签指令

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  10. jni传递对象中包含arraylist对象。

    相信在使用jni的过程中,总是要传递各种各样的类型,在这其中,我也碰到了一些问题. 简单的传一些内容,相信在网上一搜一大把. 所以我们就来说说.传递对象中包含arraylist吧. 在这里先给大家一个 ...