Problem A Lucky Year

题目传送门[here]

  题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少。

  这个幸运的数不是最高位的数字都是零,于是只跟最高位有关,只保留最高位,然后加一求差就是答案。

Code

 /**
* Codeforces
* Problem#808A
* Accepted
* Time:15ms
* Memory:0k
*/
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef bool boolean;
#define inf 0xfffffff
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} int power[]; int n;
int bits = ; inline void init() {
power[] = ;
for(int i = ; i <= ; i++)
power[i] = power[i - ] * ;
} inline void solve() {
readInteger(n);
while(power[bits] <= n) bits++;
int high = n - n % power[bits - ];
int next = high + power[bits - ];
printf("%d\n", next - n);
} int main() {
init();
solve();
return ;
}

Problem A


Problem B Average Sleep Time

题目传送门[here]

  题目大意是说,给出n个数ai和k,再得到n - k + 1个新数,第i个新数为,再求这几个新数的平均数。

  有两种方法,第一种是前缀和暴力乱搞。第二种是特殊处理两段的数被求和的次数,中间的都是k,然后就可以求和了,然后就可以求平均数。

  我呢,用的第一种方法,因为懒。

Code

 /**
* Codeforces
* Problem#808B
* Accepted
* Time:30ms
* Memory:2400k
*/
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef bool boolean;
#define inf 0xfffffff
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} #define LL long long int n, k;
LL *sum;
int* a;
double w; inline void init() {
readInteger(n);
readInteger(k);
w = n - k + ;
sum = new LL[(const int)(n + )];
a = new int[(const int)(n + )];
sum[] = ;
for(int i = ; i <= n; i++) {
readInteger(a[i]);
sum[i] = sum[i - ] + a[i];
}
} LL s = ;
double avg = 0.0; inline void solve() {
for(int i = k; i <= n; i++) {
s += sum[i] - sum[i - k];
}
avg = s / w;
printf("%.9lf", avg);
} int main() {
init();
solve();
return ;
}

Problem B


Problem C Tea Party

题目传送门[here]

  语文不好,题目大意就不给了(显然是太懒了),去看原题吧,看不懂扔给谷歌机翻。

  首先呢给每人达到最低要求的茶叶量,这时判一下是否合法。(然后跳过一个if吧)。

  接着很容易想到一个符合题意的贪心,给茶杯最大的人加尽可能多的茶叶(能加满就加满),如果还有剩的,就给茶杯第二大的人加....

  这个显然是合法,不会出现让顾客不满意的情况。

Code

 /**
* Codeforces
* Problem#808C
* Accepted
* Time:15ms
* Memory:0k
*/
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef bool boolean;
#define inf 0xfffffff
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} typedef class Teacup {
public:
int val;
int pos; Teacup(int val = , int pos = ):val(val), pos(pos) { } boolean operator < (Teacup b) const {
if(val != b.val) return val > b.val;
return pos < b.pos;
}
}Teacup; int n;
int w;
int *a;
int s = ;
int *b;
Teacup* tc; inline void init() {
readInteger(n);
readInteger(w);
a = new int[(const int)(n + )];
b = new int[(const int)(n + )];
for(int i = ; i <= n; i++) {
readInteger(a[i]);
b[i] = (a[i] + ) / ;
s += b[i];
}
} inline void solve() {
if(s > w) {
puts("-1");
return;
}
w -= s;
tc = new Teacup[(const int)(n + )];
for(int i = ; i <= n; i++)
tc[i] = Teacup(a[i], i);
sort(tc + , tc + n + );
int i = ;
while(w) {
i++;
int delta = min(w, tc[i].val - b[tc[i].pos]);
b[tc[i].pos] += delta;
w -= delta;
}
for(int i = ; i <= n; i++) {
printf("%d ", b[i]);
}
} int main() {
init();
solve();
return ;
}

Problem C

Educational Codeforces Round 21 Problem A - C的更多相关文章

  1. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  2. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  3. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  4. Educational Codeforces Round 21

    Educational Codeforces Round 21  A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...

  5. Educational Codeforces Round 21 D.Array Division(二分)

    D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  6. Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)

    A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  7. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

  8. CF Educational Codeforces Round 21

    A. Lucky Year time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Educational Codeforces Round 21 A-E题题解

    A题      ............太水就不说了,贴下代码 #include<string> #include<iostream> #include<cstring& ...

随机推荐

  1. Oracle体系结构之控制文件的多路复用技术

    在Windows操作系统中,如果注册表文件被损坏了,就会影响操作系统的稳定性.严重的话,会导致操作系统无法正常启动.而控制文件对于Oracle数据库来说,其作用就好象是注册表一样的重要.如果控制文件出 ...

  2. iOS多线程编程之NSThread的使用(转载)

    1.简介: 1.1 iOS有三种多线程编程的技术,分别是: 1.NSThread 2.Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue的 ...

  3. Python面试网络编程和并发

    1.简述 OSI 七层协议. OSI 开放系统互联参考模型,它是理论的,参考模型 七层:物理层->数据链路层->网络层->传输层->会话层->表示层->应用层 2. ...

  4. 网站搜索引擎优化(SEO)的18条守则

    1.永远不要放过网页的title,这个地方应该是你每次优化的重点. 2.请不要在title,deion,keyword里写太多东西,越是贪婪,得到的就越少. 3.网页的头部和底部是很重要的,对于搜索引 ...

  5. Javascript异步执行时要小心的变量作用域

    function asyncFunction(callback){ setTimeout(function(){ callback() },200); } var color = 'blue'; // ...

  6. MUTABLE和IMMUTABLE集合

    Scala 集合类系统地区分了可变的和不可变的集合.可变集合可以在适当的地方被更新或扩展.这意味着你可以修改,添加,移除一个集合的元素.而不可变集合类,相比之下,永远不会改变.不过,你仍然可以模拟添加 ...

  7. [dt]世纪历史长河年代表

    年代口诀 夏商与西周, 东周分两段, 春秋和战国, 一统秦两汉, 三分魏蜀吴, 二晋前后延, 南北朝并列, 隋唐五代传, 宋元明清后, 皇朝至此完. 中国历史长河年代表 参考: 中国历史朝代顺序表.年 ...

  8. Approximate Inference

    1.  Approximation    Probabilistic model  中的一个 central task :给定一组observation X 后,计算latent variables ...

  9. 1.keras实现-->使用预训练的卷积神经网络(VGG16)

    VGG16内置于Keras,可以通过keras.applications模块中导入. --------------------------------------------------------将 ...

  10. windows下编译和安装boost库

    boost是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库. 获取方式 boost提供源码形式的安装包,可以从boost官方网站下载,目前最新版本是1.59.0. 本机上正好有boos ...