C. Tennis Championship(递推,斐波那契)

题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛。
题解:
因为n太大,感觉是个构造。写写小数据,看看有没有结论。

  • 2 3 4 5 6 7 8 9 10 11 12 (人数)
  • 1 2 2 3 3 3 4 4 4 4 4 (比赛数)

发现比赛数的增长成斐波那契。维护一个前缀和即可。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100];
int main()
{
ll n;
memset(dp,0,sizeof(dp));
dp[1]=1;
dp[2]=2;
for(int i=3;i<=95;i++)
{
dp[i]=dp[i-1]+dp[i-2];
}
for(int i=1;i<=95;i++)
{
dp[i]=dp[i-1]+dp[i];
}
cin>>n;
n--;
for(int i=1;i<=95;i++)
{
if(dp[i]>=n)
{
printf("%d\n",i);
break;
}
}
}

D. Taxes(数论知识)

题意:你有值为n的财富,你需要交税,缴税方式有两种,一是直接交n的最大因子(除自身)二是将n拆成若干份>=2的部分,交他们的最大因子和。问缴税的最小值。
题解:
两个定理。三素数定理:大于2的奇数都可以拆成三个素数和的形式
哥德巴赫猜想:任一大于2的偶数都可写成两个质数之和。
然后,判断一下,有一个cha点,如果n是奇数,n-2是素数,答案为2. 大素数判定小心re。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int pan(ll p)
{
for(int i=2;i<=sqrt(p);i++)
{
if(p%i==0) return 0;
}
return 1;
}
long long n;
int main()
{
scanf("%I64d",&n);
if(pan(n))
{
cout<<1<<endl;
return 0;
}
if(n==2)
{
cout<<1<<endl;
return 0;
}
if(n%2)
{
if(pan(n-2))
cout<<2<<endl;
else
cout<<3<<endl;
}
else
{
cout<<2<<endl;
return 0;
}
}

以上代码均参考别人博客,自己水平有限,被cha了一次,好多定理不会,好多算法没学,从今天起晚上的codeforces就不参加了,调整作息,刷书做题,抱大腿学算法,越努力,越幸运!

Codeforces Round #382 Div. 2【数论】的更多相关文章

  1. 2017年浙工大迎新赛热身赛 J Forever97与寄信 【数论/素数/Codeforces Round #382 (Div. 2) D. Taxes】

    时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K64bit IO Format: %lld 题目描述 Forever97与未央是一对笔友,他们经常互 ...

  2. Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想

    D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...

  3. Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划

    C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...

  4. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  5. Codeforces Round #382(div 2)

    A.= = B. 题意:给出n个数和n1和n2,从n个数中分别选出n1,n2个数来,得到n1个数和n2个数的平均值,求这两个平均值的最大和 分析:排个序从后面抽,注意先从末尾抽个数小的,再抽个数大的 ...

  6. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  7. Codeforces Round #382 (Div. 2) 继续python作死 含树形DP

    A - Ostap and Grasshopper zz题能不能跳到  每次只能跳K步 不能跳到# 问能不能T-G  随便跳跳就可以了  第一次居然跳越界0.0  傻子哦  WA1 n,k = map ...

  8. Codeforces Round #382 (Div. 2) A. Ostap and Grasshopper bfs

    A. Ostap and Grasshopper 题面 On the way to Rio de Janeiro Ostap kills time playing with a grasshopper ...

  9. Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契

    C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. Django基础,Day8 - 管理后台定制显示

    自定义admin表单 展示效果一: from django.contrib import admin from polls.models import Question class QuestionA ...

  2. 学习MySQL之多表操作(三)

    ##多表查询 ##使用数据库 mytest USE mytest; ##删除,并重新创建表 t_dept DROP TABLE t_dept; CREATE TABLE t_dept ( deptno ...

  3. C语言基础(9)-字符串格式化输入和输出

    1.字符串在计算机内部的存储方式 字符串是内存中一段连续的char空间,以’\0’结尾 2.printf函数,putchar函数 putchar输出一个char printf是输出一个字符串 prin ...

  4. 一个简单实用的css loading图标

    摘要 在web开发中,为了提高用户体验,在加载数据的时候都会给一个loading的提示. Html <!DOCTYPE html> <html xmlns="http:// ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. 每天写点python

    1.收集系统信息python小程序 1 #!/usr/bin/env python 2 #A system information gathering script 3 4 import subpro ...

  7. 使用pm2管理nodejs应用

    PM2 is a production process manager for Node.js applications with a built-in load balancer. It allow ...

  8. php时间类

    1.需求 数据库的时间都是用10个长度的时间戳存储,拿出来的时候要转为更易读的格式 2.例子 <?php class Mydate{ public function get_millisecon ...

  9. MAC下apache+php

    mac下是自带有Apache和php的服务器的,不需要另外安装,本文就对相关配置进行介绍. 第一:Apache 在终端中输入,下面指令即可启动Apache服务器: //启动 sudo apachect ...

  10. Interleaving String

    https://leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 is formed by th ...