codeforces #516---ABC
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的更多相关文章
- [codeforces 516]A. Drazil and Factorial
[codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define ...
- codeforces#516 Div2---ABCD
A---Make a triangle! http://codeforces.com/contest/1064/problem/A 题意: 给定三个整数表示三角形的边.每次给边长可以加一,问至少要加多 ...
- codeforces CF475 ABC 题解
Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...
- Codeforces 802 ABC. Heidi and Library
题目大意 你需要保证第\(i\)天时有第\(a_i\)种书.你可以在任何一天买书,买第\(i\)种书的代价为\(c_i\). 你最多同时拥有\(k\)本书,如果此时再买书,则必须先扔掉已拥有的一本书. ...
- Codeforces 1260 ABC
DEF 题对于 wyh 来说过于毒瘤,十分不可做. A. Heating Description: 给定\(a,b\),将\(b\)分成至少\(a\)个正整数,使这些正整数的平方和最小. Soluti ...
- [CF787D]遗产(Legacy)-线段树-优化Dijkstra(内含数据生成器)
Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 ...
- 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 ...
- Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)
题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...
- 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 ...
- Codeforces Round #516 (Div. 2) (A~E)
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...
随机推荐
- Oracle-05-SQL语句概述、分类&SQL*PLUS概述(初识insert,desc,list,r,del,a,c,n等命令)
一.SQL语句概述 (1)SQL全程是"结构化查询语言(Structured Query Language)". SQL是大多数主流数据库系统採用的标准查询语言. (2)SQL语句 ...
- Ubuntu 14.04 安装R 环境
Introduction R is a popular open source programming language that specializes in statistical computi ...
- Nginx配置PATHINFO隐藏index.php
1.网络来源:http://www.shouce.ren/post/view/id/1529 server { listen 80; default_type text/ ...
- php获取当月的第一天以及最后一天
<?php header("Content-Type:text/html;charset=utf-8"); $date = date("Y-m-d H:i:s&qu ...
- uniqid,md5,microtime
<?php header("content-type:text/html;charset=utf-8"); $str = uniqid(md5(microtime(true) ...
- c++获取cpu信息
原文地址:http://blog.csdn.net/jamesliulyc/article/details/2028958 1.什么是cpuid指令 CPUID指令是intel IA32架构下获得CP ...
- Java基础-JDBC访问数据库
基本步骤: 加载数据库驱动 建立连接 创建SQL语句 执行SQL语句 处理执行结果 释放资源 代码示例: import java.sql.Connection; import java.sql.Dri ...
- c++ list sort
1. bool operator < (S & b) { return ID < b.ID; } struct S { std::string firstn ...
- MathType在手,公式不求人!
很多论文达人们的论文排版是相当漂亮的,页面也非常整齐美观,即使是理工类的论文,里面有很多的数学符号和公式,排版也是非常整洁,为什么达人们的公式论文能排版的这么完美,而自已却总是不得其门而入,最后只好救 ...
- 巧妙的利用Mongodb做地理空间查询