A. Fake NP

传送门:http://codeforces.com/contest/805/problem/A

本题是一个数学问题。

给定两个正整数l,r(l≤r),对于区间[l..r]上的任一整数,写出其除1以外的所有因数,求区间[l..r]上出现频率最高的一个因数。

结论:若l=r,则答案为l(或r),否则为2。参考程序如下:

#include <stdio.h>

int main(void)
{
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", l == r? l: );
return ;
}

B. 3-palindrome

传送门:http://codeforces.com/contest/805/problem/B

本题是一个构造问题。

一个长度为n的字符串,每一个字符是‘a’、‘b’、‘c’三个字符中的一个。这个字符串不存在长度为3的回文,且字符‘c’出现的频率尽可能低。生成一个满足上述条件的字符串。

这个字符串可以是以下的形式:

aabbaabbaabb...

参考程序如下:

#include <stdio.h>

int main(void)
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)
putchar(i & ? 'b': 'a');
return ;
}

C. Find Amir

传送门:http://codeforces.com/contest/805/problem/C

本题是一个数学问题。

n个点,从点i到点j的代价是(i+j)mod(n+1)。求遍历这n个点的最小代价。

这个问题看似是一个最短路(Shortest Path)问题。但实际上,这个问题也可以被看作是一个数学问题。

i+j=n+1,则从点i到点j的代价为0。如以下的{i,j}组合:

{1,n},{2,n-1},...,{i+1,n-i},...。

因此,可以设置遍历顺序:1→n→2→n-1...→i→n+1-i→i+1→n-i→...。

a.若n=2k(k=1,2,...),则遍历顺序:1→n→2→n-1...k-1k+1k

b.若n=2k-1(k=1,2,...),则遍历顺序:1→n→2→n-1...k-2k+1k-1k

以上情形的最小代价均为k-1。参考程序如下:

#include <stdio.h>

int main(void)
{
int n;
scanf("%d", &n);
printf("%d\n", (n - ) / );
return ;
}

Codeforces 805A/B/C的更多相关文章

  1. 【codeforces 805A】Fake NP

    [题目链接]:http://codeforces.com/contest/805/problem/A [题意] 问你在l..r这个区间内的所有数字: 对于每个数的因子; 出现次数最多的是哪一个; [题 ...

  2. Fake NP CodeForces - 805A (思维)

    Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following pro ...

  3. CodeForces 805A Fake NP

    直觉. 一段区间中,肯定是$2$的倍数最多,因为区间长度除以$2$得到的数字最大.但只有$1$个数字的时候需要特判. #include <cstdio> #include <cmat ...

  4. codeforces——数学

    codeforces 805A     http://codeforces.com/problemset/problem/805/A /* 题意:输入两个整数l,r,让你找一个因子 使得[l,r]里面 ...

  5. codeforces411div.2

    每日CF: 411div2 Solved A CodeForces 805A Fake NP Solved B CodeForces 805B 3-palindrome Solved C CodeFo ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. 蒟蒻的数位DP专题总结

    BZOJ  1026: [SCOI2009]windy数: 题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1026           d ...

  2. bzoj4950: [Wf2017]Mission Improbable

    跟着靖靖做题%%%%% 这题一看就觉得和之前的某场模拟赛的一道题很像,找假如某行某列的最大值一样的就可以只堆一个,跑匈牙利就行 一开始以为箱子不能移动-_-! 然后有个坑,大家都知道当这个位置有箱子就 ...

  3. Android WiFi开发教程(三)——WiFi热点数据传输

    在上一篇文章中介绍了WiFi的搜索和连接,如果你还没阅读过,建议先阅读上一篇Android WiFi开发教程(二)——WiFi的搜索和连接.本篇接着简单介绍手机上如何通过WiFi热点进行数据传输. 跟 ...

  4. [NOIP 2016] 蚯蚓

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4721 [算法] 首先,我们可以维护一个堆,堆中存放蚯蚓的长度,由于除当前蚯蚓其他的蚯 ...

  5. How to add dependency on a Windows Service AFTER the service is installed

    his can also be done via an elevated command prompt using the sc command. The syntax is: sc config [ ...

  6. the user must supply a jdbc connection 错误解决方法

    转自:https://blog.csdn.net/actionzh/article/details/54200451 今天在配置hibernate之后,进行添加数据测试时,运行中报出了 the use ...

  7. HTML中的文本框textarea标签

    转自:https://www.jb51.net/web/183411.html <textarea></textarea>用来创建一个可以输入多行的文本框,此标志对用于< ...

  8. git使用简易指南(转)

    创建新仓库 创建新文件夹,打开,然后执行 git init以创建新的 git 仓库. 检出仓库 执行如下命令以创建一个本地仓库的克隆版本:git clone /path/to/repository 如 ...

  9. fopen文件目录问题

    程序当前目录下.如果是在 VC 里面运行的, 这个目录是工程的目录. 如果是双击 exe 运行的, 这个目录就是 exe 所在的目录.

  10. html5 读取本地文件

    尊重原创:http://hushicai.com/2014/03/29/html5-du-qu-ben-di-wen-jian.html HTML5为我们提供了一种与本地文件系统交互的标准方式:Fil ...