[Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)

题目链接:http://codeforces.com/problemset/problem/334/C

题目:

题目大意:

给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S大于n,且删掉数列中的任意一个元素数列之和都会小于n,最小化这个数列的长度

题解:

我们考虑从小到大枚举k,取最小的k,使得,答案就是$n/3^k+1$

为什么呢?

我们考虑一个合法的数列,其中最小的元素是A,那么S一定是A的倍数。假设n是A的倍数,又S>n,那么S-A>=n,这样的话去掉A这个数列依旧大于等于n,数列就不合法了。

所以我们有n一定不是A的倍数。

于是我们从小到大枚举A的大小,直到找到最小的A满足n不是A的倍数,那么就直接用面值为A的硬币就可以了。

也许有为什么不用更大的满足n不是A的倍数的A的疑惑,其实更大的话也都可以表示成最小的A的倍数,那显然是没有用A优的

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

long long n;
int main()
{
    cin>>n;
    while(n%3==0)
    {
        n/=3;
    }
    cout<<n/3+1<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/xxzh/p/9614203.html

时间: 2024-08-05 10:17:23

[Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)的相关文章

Codeforces Round 319 # div.1 &amp; 2 解题报告

Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1<=x<=10^9 题解: 送分题…对于每一行,判断是否存在数x即可…也可以枚举x的因子判断是否出现在表内… #include<cstdio>#include<cstring>inlineint read(){int s =0;char c;while((c=getchar())

CodeForce---Educational Codeforces Round 3 The best Gift 解题报告

对于这题笔者认为可以用数学排列来算,但是由于笔者很懒所以抄了一段大神的代码来交个大家了, 这位大神的基本想法就是通过记录各类书的数量,再暴力破解: 下面贴出这位大神的代码吧: 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 6 int h[15]; 7 int main() 8 { 9 int n,m; 10 scanf("%d%d&q

Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)

链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are r candies in it, the second pile contains only green candies and there are g ca

Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

给定一个直角三角形的一边长度.问是否存在一个直角三角形,使得它满足有一边的长度是x 当x=1.2的时候是无解的,可以暴力打表看看. 注意到,相邻的两个数的平方的差值是奇数 x^2 - (x-1)^2 = 2*x-1 间隔为2的两个数的平方的差值是偶数 (x+1)^2 - (x-1)^2 = 4*x 这样就可以分类讨论了. 把n永远当成是指角边就OK #include <cstdio> #include <cstdlib> #include <cstring> #incl

Codeforces Round #273 (Div. 2)C. Table Decorations 数学

C. Table Decorations You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be

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

终于重上DIV1了.... A:在正方形中输出一个菱形 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月01日 星期五 23时27分55秒 4 5 #include<vector> 6 #include<set> 7 #include<deque> 8 #include<stack> 9 #include<bitset> 10 #inclu

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

详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http://codeforces.com/contest/460/problem/A 有n双袜子,每天穿一双然后扔掉,每隔m天买一双新袜子,问最多少天后没有袜子穿.. 简单思维题:以前不注重这方面的训练,结果做了比较久,这种题自己边模拟边想.不过要多考虑trick ```c++ int main(){ i

Codeforces Round #615(Div.3)解题报告

Codeforces Round #615(Div.3)解题报告 A. Collecting Coins 注意\(n\)可能不够用的情况. #include<bits/stdc++.h> using namespace std; typedef long long ll; int a, b, c, n; void solve() { cin >> a >> b >> c >> n; int mx = max(max(a, b), c); int

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

Codeforces Round #616 (Div. 2)解题报告 A. Even But Not Even 找两个奇数就行了. #include<bits/stdc++.h> using namespace std; void solve() { int n; string s; cin >> n >> s; string ans = ""; for(int i = 0; i < n; i++) { if(int(s[i] - '0')%2