题意: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. 批量修改文件的编码格式至UTF-8

    批量修改文件的编码格式至UTF-8 学习了: https://jingyan.baidu.com/article/e8cdb32b47a1ea37042bad11.html http://blog.c ...

  2. 代理server poll version

    poll和select一样,管理多个描写叙述符也是进行轮询,依据描写叙述符的状态进行处理,可是poll没有最大文件描写叙述符数量的限制,select is 1024/2048 #include &qu ...

  3. android openGL ES2 一切从绘制纹理開始

    纹理.在openGL中,能够理解为载入到显卡显存中的图片.Android设备在2.2開始支持openGL ES2.0.从前都是ES1.0 和 ES1.1的版本号.简单来说,openGL ES是为了嵌入 ...

  4. less06 引入(importing)

    main.less @wp:960px; .colorsss{ color: darkgreen; } index.css .color{ color: #ff6600; } style.less / ...

  5. Pocket英语语法---二、指示代词和不定代词是什么

    Pocket英语语法---二.指示代词和不定代词是什么 一.总结 一句话总结: 指示代词:标识人或事物的代词,用来代替前面已提到过的名词 this.these.that.those不定代词:指代不确定 ...

  6. Windows安装PHP MongoDB扩展

    本文将讲述一下在Wamp环境下安装MongoDB扩展的过程,大家可以略作参考 Linux 版本的可以参考之前发布的Linux安装PHP MongoDB扩展 安装环境 系统环境:Windows 7 64 ...

  7. Python Schema使用说明

    转自https://segmentfault.com/a/1190000011777230 Python Schema使用说明 Schema是什么? 不管我们做什么应用,只要和用户输入打交道,就有一个 ...

  8. Oracle数据库Helper类

    using System;using System.Collections.Generic;using System.Data;using System.Data.OleDb;using System ...

  9. PC/H5端各浏览器兼容性问题及解决方案?

    概念:所谓的浏览器兼容性问题,是指因为不同的浏览器对同一段代码解析的差异,造成页面显示效果不统一的情况. 1>不同浏览器的标签默认的外补丁和内补丁不同问题症状:随便写几个标签,不加样式控制的情况 ...

  10. 基于JavaSwing的例子-非连接数据库

    项目结构: Constant.java package com.mstf.test; import java.io.Serializable; public class Constant implem ...