题意: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. c++PrimerChap8IO库

    #include<iostream> #include<fstream> #include<string> using namespace std; int mai ...

  2. php把数据表导出为Excel表的最简单、最快的方法(不用插件)

    亲测可用,把下面的数据换成自己的即可 <?php header("Content-type:application/vnd.ms-excel");header("C ...

  3. Adobe Flex迷你教程 —Flex圆角容器

    在Flex3时代可以设置borderSides属性达到圆角效果,如:borderSides="top left right" ,在Flex4中borderSides属性貌似已经没有 ...

  4. 没用私服,自己安装下本地jar包,制作坐标

    没用私服的话,自己安装下本地jar包吧.执行下面命令即可. -Dfile 代表jar存在路径.mvn install:install-file -DgroupId=alipay -DartifactI ...

  5. SQLSever: 怎样在select中的每一行产生不同的随机数?

    select 的随机函数有点假, 或许是由于它是基于时间来的吧, 同一select中由于时间无法错开导致产生的随机数都是一样的. 怎样做到让不同的行拥有不同的随机数呢? 以下以产生某个月的随机日期来演 ...

  6. ubuntu,jdk安装成功后,点击eclipse,提示信息A Java RunTime Environment (JRE) or Java Development Kit (JDK)

    A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Ecl ...

  7. Find or Query Data with the mongo Shell

    https://docs.mongodb.com/getting-started/shell/query/ Overview You can use the find() method to issu ...

  8. zzulioj--1776--和尚特烦恼2——第几个素数(技巧模拟)

    1776: 和尚特烦恼2--第几个素数 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 267  Solved: 100 SubmitStatusWeb ...

  9. Edge浏览器开发人员工具

    UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Ch ...

  10. RelativeLayout中的baseline

    比如,加入两个相邻的TextView,给第二个TextView一个大一点的padding(比如20dp),如果加了layout_alignBaseline到第二个TextView中的话, TextVi ...