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. 线段树+离线 hdu5654 xiaoxin and his watermelon candy

    传送门:点击打开链接 题意:一个三元组假设满足j=i+1,k=j+1,ai<=aj<=ak,那么就好的.如今告诉你序列.然后Q次询问.每次询问一个区间[l,r],问区间里有多少个三元组满足 ...

  2. leetcode第一刷_Same Tree

    回来更博客的时候才发现.这道题不是跟推断树是不是对称的很相像吗.这个也是用了两个指针同一时候递归啊,有时候思维的局限真可笑. class Solution { public: bool isSameT ...

  3. oc31--new实现

    // // main.m // new方法实现原理 #import <Foundation/Foundation.h> #import "Person.h" int m ...

  4. 应用程序 /dev/rtc 编程 获取时间 2011-12-13 01:01:06【转】

    本文转载自:http://blog.chinaunix.net/uid-16785183-id-3040310.html 分类: 原文地址:应用程序 /dev/rtc 编程 获取时间 作者:yuwei ...

  5. C++中的inline的用法

    C++中的inline的用法  参考:http://www.cnblogs.com/fnlingnzb-learner/p/6423917.html 1. 引入inline关键字的原因 在c/c++中 ...

  6. mac os lscpu 【转】

    CPU Information on Linux and OS X This is small blog post detailing how to obtain information on you ...

  7. 97. ExtJS之EditorGridPanel afteredit属性

    转自:https://zccst.iteye.com/blog/1328869 1. 之前大多用Ext.grid.GridPanel,现在需要可编辑功能,发现比以前稍复杂一些. 就是需要对指定列进行可 ...

  8. Watchcow(欧拉回路)

    http://poj.org/problem?id=2230 题意:给出n个field及m个连接field的边,然后要求遍历每条边仅且2次,求出一条路径来. #include <stdio.h& ...

  9. selenium3 + python 操作浏览器基本方法

    from selenium import webdriverimport time as t # driver = webdriver.Chrome()# driver.get("http: ...

  10. Windows7环境下Composer 安装包的Cache目录位置

    http://segmentfault.com/a/1190000000355928 https://getcomposer.org/doc/ 要说Composer的用法,以后再说,现在只记录wind ...