A---golden plate

http://codeforces.com/contest/1072/problem/A

题意:给一个n*m的格子,从最外层往里涂色,每次尽量涂最外面的那一圈,两圈涂色之间要间隔一格。问最多涂多少颜色。

思路:最外面一圈是2*n + 2(m - 2),然后行和列都减4就行了。里面的if都可以不用写,因为数据范围已经保证了

 #include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f int w, h, k; int main()
{
while(scanf("%d%d%d", &w, &h, &k) != EOF){ int ans = ;
for(int i = ; i < k; i++){
if(w <= || h <= )break;
if(h >= ){
ans += * w + * (h - );
}
else if(h >= ){
ans += w;
}
w -= ; h -= ; }
printf("%d\n", ans);
}
return ;
}

好的这是我这次比赛唯一过了的题目 吐血又猛的掉分了。

B---Curiosity Has No Limits

题意:给两个数量为n-1的数列a,b

a[i] = t[i] | t[i+1],  b[i] = t[i] & t[i+1],问是否可以找到这样的数列c

思路:因为a和b的数保证是在0~3.所以只有三种情况,对于所有的i,可以知道有可能的t[i]和t[i+1]

枚举最开始的数的两种可能,然后暴力跑一遍看看能不能符合。

一直WA在了第8组是因为,当a=3,b=0时,t可以是0/3, 也可以是1/2, 所以每当是这样的情况的时候要多考虑一下

 #include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f int n;
const int maxn = 1e5 + ;
int a[maxn], b[maxn], c[maxn]; int check()
{
for(int i = ; i <= n - ; i++){
if(a[i] == && b[i] != ){
return -;
}
else if(b[i] == && a[i] != ){
return -;
}
else if(b[i] == && a[i] == ){
return -;
}
else if(b[i] == && a[i] == ){
return -;
}
else{
int x, y, l, k;
if(b[i] == ){
x = ;
y = a[i];
if(a[i] == ){
l = ;
k = ;
}
}
else if(b[i] == ){
x = y = ;
}
else if(b[i] == ){
if(a[i] == ){
x = y = ;
}
else{
x = ;
y = ;
}
}
else if(b[i] == ){
if(a[i] == ){
x = y = ;
}
else{
x = ;
y = ;
}
}
if(c[i] == x){
c[i + ] = y;
}
else if(c[i] == y){
c[i + ] = x;
}
else if(b[i] == && a[i] == ){
if(c[i] == l){
c[i + ] = k;
}
else if(c[i] == k){
c[i + ] = l;
}
else return ;
}
else{
return ;
}
}
}
return ;
} int main()
{
while(scanf("%d", &n) != EOF){
for(int i = ; i <= n - ; i++){
scanf("%d", &a[i]);
}
for(int i = ; i <= n - ; i++){
scanf("%d", &b[i]);
} bool flag = true;
int tmp1, tmp2, tmp3, tmp4;
if(a[] == && b[] != ){
flag = false;
}
else if(b[] == && a[] != ){
flag = false;
}
else if(b[] == && a[] == ){
flag = false; }
else if(b[] == && a[] == ){
flag = false; }
else if(b[] == ){
tmp1 = ;
tmp2 = a[];
if(a[] == ){
tmp3 = ;
tmp4 = ;
}
}
else if(b[] == ){
tmp1 = tmp2 = ;
}
else if(b[] == ){
if(a[] == ){
tmp1 = tmp2 = ;
}
else{
tmp1 = ;
tmp2 = ;
}
}
else if(b[] == ){
if(a[] == ){
tmp1 = tmp2 = ;
}
else{
tmp1 = ;
tmp2 = ;
}
} if(!flag){
printf("NO\n");
continue;
}
/*if(n == 2){
printf("YES\n%d %d\n", tmp1, tmp2);
continue;
}*/
c[] = tmp1;
c[] = tmp2;
int f = check();
if(f == -){
printf("NO\n");
}
else if(f == ){
c[] = tmp2;
c[] = tmp1;
int x = check();
if(x == ){
printf("YES\n");
printf("%d", c[]);
for(int i = ; i <= n; i++){
printf(" %d", c[i]);
}
printf("\n");
}
else if(x == ){
if(b[] == && a[] == ){
c[] = tmp3;
c[] = tmp4;
int y = check();
if(y == ){
printf("YES\n");
printf("%d", c[]);
for(int i = ; i <= n; i++){
printf(" %d", c[i]);
}
printf("\n"); }
else if(y == ){
c[] = tmp4;
c[] = tmp3;
int z = check();
if(z == ){
printf("YES\n");
printf("%d", c[]);
for(int i = ; i <= n; i++){
printf(" %d", c[i]);
}
printf("\n"); }
else{
printf("NO\n");
}
}
}
else{
printf("NO\n");
}
}
}
else if(f == ){
printf("YES\n");
printf("%d", c[]);
for(int i = ; i <= n; i++){
printf(" %d", c[i]);
}
printf("\n");
}
}
return ;
}

C---Cram Time

题意:告诉你两天的时间长度a,b,学第i门课需要i个小时,并且不可以拆分到两天学。现在想要尽量多学习,问每天应该学习哪几门课。

思路:因为要尽量多的学,所以应该尽量选择前面的课程。我们先找出前x个之和小于等于a+b的最大的x,他就是总的学习科目数。

从大到小给第一天尽量去分配,当a学习第i个不够时,就跳过i给他挑一个小一些的刚好填进去的。

剩下的都是给b的。

注意要用longlong

 #include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f
#define lld I64d LL a, b;
const int maxn = 1e5 + ;
bool vis[maxn]; int main()
{
while(scanf("%lld%lld", &a, &b) != EOF){
memset(vis, , sizeof(vis));
LL ans = (sqrt( + * (a + b)) - ) / ;
//cout<<ans<<endl;
LL n = ;
for(LL i = ans; i >= ; i--){
if(a - i >= ){
vis[i] = true;
a -= i;
n++;
}
}
printf("%lld\n", n);
bool flag = false;
for(LL i = ans; i >= ; i--){ if(vis[i]){
if(flag){
printf(" ");
}
else{
flag = true;
}
printf("%lld", i);
}
}
printf("\n"); printf("%lld\n", ans - n);
flag = false;
for(LL i = ; i <= ans; i++){
if(!vis[i]){
if(flag){
printf(" ");
}
else{
flag = true;
}
printf("%lld", i);
}
}
printf("\n"); }
return ;
}

codeforces #516---ABC的更多相关文章

  1. [codeforces 516]A. Drazil and Factorial

    [codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define  ...

  2. codeforces#516 Div2---ABCD

    A---Make a triangle! http://codeforces.com/contest/1064/problem/A 题意: 给定三个整数表示三角形的边.每次给边长可以加一,问至少要加多 ...

  3. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  4. Codeforces 802 ABC. Heidi and Library

    题目大意 你需要保证第\(i\)天时有第\(a_i\)种书.你可以在任何一天买书,买第\(i\)种书的代价为\(c_i\). 你最多同时拥有\(k\)本书,如果此时再买书,则必须先扔掉已拥有的一本书. ...

  5. Codeforces 1260 ABC

    DEF 题对于 wyh 来说过于毒瘤,十分不可做. A. Heating Description: 给定\(a,b\),将\(b\)分成至少\(a\)个正整数,使这些正整数的平方和最小. Soluti ...

  6. [CF787D]遗产(Legacy)-线段树-优化Dijkstra(内含数据生成器)

    Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 ...

  7. 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 ...

  8. Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)

    题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...

  9. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth

    http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,…… 求的是最少的步数,所以使用bfs. step=k ...

  10. Codeforces Round #516 (Div. 2) (A~E)

    目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...

随机推荐

  1. repo manifest.xml 分析

    repo是用于管理android的git仓库的工具. 之前想将android的代码放在github上面,并通过repo进行管理.但一直不知道怎么添加进去,那么多的git仓库,难道都要手动建立吗? 直到 ...

  2. C++中函数的返回值

    原文 [ 函数的返回值用于初始化在调用函数处创建的临时对象.在求解表达式时,如果需要一个地方储存其运算结果,编译器会创建一个没有命名的对象,这就是 临时对象.temporary object ] -- ...

  3. windows 批处理文件中引用日期

    参见:http://blog.csdn.net/iw1210/article/details/39313677 %DATE%输出的是: yyyy/mm/dd 星期* (例如:2008/12/18 星期 ...

  4. e680. 使三元色图像变明变暗

    This example demonstrates how to brighten or darken an RGB buffered image by scaling the red, green, ...

  5. C++ 数据封装

    C++ 数据封装所有的 C++ 程序都有以下两个基本要素: 程序语句(代码):这是程序中执行动作的部分,它们被称为函数.程序数据:数据是程序的信息,会受到程序函数的影响.封装是面向对象编程中的把数据和 ...

  6. javascript -- 原型对象

    原型对象: 每个对象都有一个参考对象,这个参考对象称之为原型对象.原型对象有自己的属性和方法.当A是B的原型对象时,那 么B拥有A中的所有属性和方法. 原型对象的工作原理: 使用原型对象定义一个新的对 ...

  7. mac下普通用户无法创建crontab的问题解决

    想在mac下弄一个crontab定时任务,以为会像linux上那样顺利那,结果碰壁了,报错信息例如以下: ➜  autoshell  crontab -ecrontab: no crontab for ...

  8. u3d调用自己的dll

    原文地址:http://blog.sina.com.cn/s/blog_62f7cb730100zhhf.html 首先用vc建立一个dll工程 然后在里面建立一个testunity.h文件.内容如下 ...

  9. 如何查看linux命令源代码

    如何查看linux命令源代码 用linux一段时间了,有时候想看看ls.cat.more等命令的源代码,在下载的内核源码中用cscope没能找到,在网上搜索了一下,将方 法总结如下: 以搜索ls命令源 ...

  10. [转]ASP.NET MVC 5 - 查询Details和Delete方法

    在这部分教程中,接下来我们将讨论自动生成的Details和Delete方法. 查询Details和Delete方法 打开Movie控制器并查看Details方法. public ActionResul ...