CF398A Cards | 贪心
我怎么连这种题都做得那么艰难……
可以发现一些结论,然后枚举'x'被分成几段就好了。
我真的越来越菜
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int cnt[100005];
int main()
{
int a=0,b=0,c=0;
long long ans=-1e18;
scanf("%d%d",&a,&b);
if(b==0)
{
printf("%I64d\n",(long long)a*a);
for(int i=1;i<=a;i++) putchar('o');
return 0;
}
for(int i=1;i<=min(a+1,b);i++)
{
long long x=b/i,y=b%i,k=max(0,i-2);
long long w=-i*x*x-y*(2*x+1);
w+=k+(long long)(a-k)*(a-k);
if(w>ans) ans=w,c=i;
}
printf("%I64d\n",ans);
for(int i=1;i<=c;i++) cnt[i]=b/c;
for(int i=1;i<=b%c;i++) cnt[i]++;
for(int i=1;i<=c-1;i++)
{
if(i>1) putchar('o');
for(int j=1;j<=cnt[i];j++)
putchar('x');
}
for(int i=1;i<=a-c+2-(c==1);i++) putchar('o');
for(int j=1;j<=cnt[c];j++) putchar('x');
return 0;
}
CF398A
CF398A Cards | 贪心的更多相关文章
- CodeForces - 777B Game of Credit Cards 贪心
题目链接: http://codeforces.com/problemset/problem/777/B 题目大意: A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并 ...
- Game of Credit Cards(贪心+思维)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- Cards and Joy CodeForces - 999F (贪心+set)
There are nn players sitting at the card table. Each player has a favorite number. The favorite numb ...
- Codeforces 777B:Game of Credit Cards(贪心)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- 【贪心】【multiset】 Codeforces Round #401 (Div. 2) B. Game of Credit Cards
对第一个人的排序,然后从小到大处理,对第一个人的每枚卡片,从第二个人的卡片中选择一个大于等于它的最小的,否则选择一个当前剩下的最小的,这样可以保证负场最少. 如果选择的改成大于它的最小的,就可以保证胜 ...
- 【Yellow Cards CodeForces - 1215A 】【贪心】
该题难点在于求最小的离开数,最大的没什么好说的,关键是求最小的. 可以这样去想,最小的离开数就是每个人获得的牌数等于他所能接受的最大牌数-1,这样就可以直接比较m=a1(k1-1)+a2(k2-1)与 ...
- NUC_TeamTEST_B(贪心)
B - B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Alice and Bob(贪心HDU 4268)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU4268 Alice and Bob(贪心+multiset)
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
随机推荐
- DP 习题
一.简单基础dp 这类dp主要是一些状态比较容易表示,转移方程比较好想,问题比较基本常见的.主要包括递推.背包.LIS(最长递增序列),LCS(最长公共子序列),下面针对这几种类型,推荐一下比较好的学 ...
- PTA面向对象程序设计6-3 面积计算器(函数重载)
实现一个面积计算器,它能够计算矩形或长方体的面积. 函数接口定义: int area(int x, int y); int area(int x, int y, int z); 第一个函数计算长方形的 ...
- java的运行时数据区域
最近在看<深入理解Java虚拟机>,书中给了几个例子,比较好的说明了几种OOM(OutOfMemory)产生的过程,大部分的程序员在写程序时不会太关注Java运行时数据区域的结构: 1.程 ...
- 3. Go并发编程--数据竞争
目录 1.前言 2.数据竞争 2.1 示例一 2.1.1 测试 2.1.2 data race 检测 2.1.3 data race 配置 2.2 循环中使用goroutine引用临时变量 2.3 引 ...
- @RestController的用法
我一直都不太理解RESTFUL风格但是先记住一些基本用法在深入吧 ** * * 在服务端应用程序状态和功能可以分成各种资源,每一个资源都使用URL 得到一个唯一的地址,所有资源都共享统一的 * 接口, ...
- 主动开启进程与join方法
使用multiprocessing.Process来开启进程 import os import time from multiprocessing import Process def eat(): ...
- @Valid注解的一点理解
@Valid注解存在于spring-boot-starter-web包下,只要项目中存在该依赖就无需自行导入,也就是说该注解适用于springboot项目此注解用于表单验证,简化了判断代码用法:格式如 ...
- 在CentOS 6中安装和配置OrientDB社区版
OrientDB概述: OrientDB是一个开源NoSQL非关系型数据库管理系统. NoSQL数据库提供了一种用于存储和检索引用除表式数据之外的数据(例如文档数据或图形数据)的NO关系或非关系数据的 ...
- python测试开发工具库汇总(转载)
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
- 深入剖析 Spring WebFlux
一.WebFlux 简介 WebFlux 是 Spring Framework5.0 中引入的一种新的反应式Web框架.通过Reactor项目实现Reactive Streams规范,完全异步和非阻塞 ...