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. android 细节之 menu 之 invalidateOptionsMenu

    menu 在 android中是个很经常使用的控件,曾经自己做项目的时候通常都是将系统的menu相关方法在activity中直接删去.而且将主题换为fullscreen,然后再在layout中引入自己 ...

  2. VIM 移动

    基础 字符移动 k 上移 k h 左移 h l l 右移 j j 下移 你也可以使用键盘上的方向键来移动,但这么做h j k l的存在就失去了意义 之所以使用h j k l来控制方向,其主要目的是让你 ...

  3. WinForm c# 备份 还原 数据库(Yc那些事儿 转)

    Yc那些事儿 我愿意 为了我的幸福 奋斗终生     2008-11-17 18:04 WinForm c# 备份 还原 数据库 其实是个非常简单的问题,一个Form,一个Button,一个OpenF ...

  4. Tool:ProcessOn

    ylbtech-Tool:ProcessOn ProcessOn是一个面向垂直专业领域的作图工具和社交网络,成立于2011年6月并于2012年启动.ProcessOn将全球的专家顾问.咨询机构.BPM ...

  5. tensorflow在windows操作系统上的安装

    在电脑上安装PyCharm和Python3,然后把Python3的安装路径写进系统变量里,Python安装完之后, https://bootstrap.pypa.io/get-pip.py,把这页的代 ...

  6. Coursera Algorithms Programming Assignment 1: Percolation(100分)

    题目来源http://coursera.cs.princeton.edu/algs4/assignments/percolation.html 作业分为两部分:建立模型和仿真实验. 最关键的部分就是建 ...

  7. 洛谷P2916 [USACO08NOV]为母牛欢呼(最小生成树)

    P2916 [USACO08NOV]为母牛欢呼Cheering up the C… 题目描述 Farmer John has grown so lazy that he no longer wants ...

  8. UITextField 点击事件 --- 不会触发键盘弹出,触发其他事件的实现。

    今天在做项目的过程中,其中有三个控件: UITextField, UITextView , UILabel, 后来发现个问题:如果什么数据都不回填给textField.text 和 textView. ...

  9. BZOJ 1975 k短路 A*

    思路: 直接上A* //By SiriusRen #include <queue> #include <cstdio> #include <cstring> #in ...

  10. A - Fox And Snake

    Problem description Fox Ciel starts to learn programming. The first task is drawing a fox! However, ...