小白题解 Codeforces 804A Find Amir
来源:互联网 发布:软件盒子网站 编辑:程序博客网 时间:2024/06/06 19:17
(水题)题目链接:点击打开链接
题目大意:给定编号为1到n的点,一个人从一点出发走完这n个点,每段的花费为(i+j)mod(n+1),求最小花费
分析:由于花费是要(i+j)mod(n+1),则尽可能使每段路程的i+j都接近n+1,通过样例中n=10的情况,不难发现解法。从1到n,花费为0;从n走到2,花费为1;从2到n-1,花费为0;从n-1到3,花费为1;从3到n-2...这样循环往复,每次向右走花费为零,向左走花费为1。据此不难写出通项公式:cost =(n-1)mod 2。
下面是AC代码
#include<cstdio>int main(){ int n; scanf("%d",&n); printf("%d\n",(n-1)/2); return 0;}
阅读全文
0 0
- 小白题解 Codeforces 804A Find Amir
- codeforces 804A Find Amir
- codeforces 804A——Find Amir
- 【Codeforces Round #411 (Div. 1)】Codeforces 804A Find Amir
- CodeFroces 804A Find Amir
- CF#804 A. Find Amir(贪心)
- A. Find Amir
- CodeForces 805C Find Amir
- Codeforces 805C Find Amir
- codeforces 411 div2-find amir
- 小白题解 Codeforces 785A
- Codeforces Round #411 C. Find Amir
- Find Amir
- Codeforces Round #411(A. Fake NP; B. 3-palindrome; C. Find Amir; D.Minimum number of steps)
- 小白题解 Codeforces 794A Bank Robbery
- 小白题解 Codeforces 805A Fake NP
- 小白题解 Codeforces 807A Is it rated?
- 小白题解 Codeforces 798A Mike and palindrome
- PrintWriter打印流实例
- <第二行代码>中的天气应用
- [PHP]
- okhttp多图上传
- CentOS 下配置vsftpd,匿名可上传可下载
- 小白题解 Codeforces 804A Find Amir
- mysql中TIMESTAMP设置默认值的灵活运用
- python参数的传入 * ,**
- computed和methods里面使用switch分别处理
- Linux下实现myshell的重定向
- KM算法模板(二分图的最大权匹配)
- scrapy newspaper bug
- UIButton的titleEdgeInsets和imageEdgeInsets属性
- Unity使用shareSDK做微信登录时无法实现的解决办法