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, ... 
随机推荐
- C# 动态构建表达式树(二)——构建 Select 和 GroupBy 的表达式
			C# 动态构建表达式树(二)--构建 Select 和 GroupBy 的表达式 前言 在上篇中写了表达式的基本使用,为 Where 方法动态构建了表达式.在这篇中会写如何为 Select 和 Gro ... 
- 【PHP数据结构】其它排序:简单选择、桶排序
			这是我们算法正式文章系列的最后一篇文章了,关于排序的知识我们学习了很多,包括常见的冒泡和快排,也学习过了不太常见的简单插入和希尔排序.既然今天这是最后一篇文章,也是排序相关的最后一篇,那我们就来轻松一 ... 
- 2.docker安装及原理
			一. docker的架构 1.1 docker的架构 先来看docker官网给出的docker架构图: 看官网,docker的架构描述: https://docs.docker.com/get-sta ... 
- Ubuntu怎么开启/关闭防火墙
			在Ubuntu中,使用sudo ufw status命令查看当前防火墙状态. 不活动,是关闭状态. 在Ubuntu中,使用sudo ufw enable命令来开启防火墙. 在Ubuntu中,使用sud ... 
- django 使用装饰器验证用户登陆
			使用装饰器验证用户登陆,需要使用@method_decorator 首先需引用,method_decorator,并定义一个闭包 from django.utils.decorators import ... 
- 鸿蒙内核源码分析(GN应用篇) | GN语法及在鸿蒙的使用 | 百篇博客分析OpenHarmony源码 | v60.01
			百篇博客系列篇.本篇为: v60.xx 鸿蒙内核源码分析(gn应用篇) | gn语法及在鸿蒙的使用 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙 ... 
- P6640-[BJOI2020]封印【SAM,二分】
			正题 题目链接:https://www.luogu.com.cn/problem/P6640 题目大意 给出两个字符串\(s,t\).\(q\)次给出\(l,r\)询问\(s_{l\sim r}\)与 ... 
- 如何基于Security实现OIDC单点登录?
			一.说明 本文主要是给大家介绍 OIDC 的核心概念以及如何通过对 Spring Security 的授权码模式进行扩展来实现 OIDC 的单点登录. OIDC 是 OpenID Connect 的简 ... 
- eclipse下载安装
			1.下载 网址:https://www.eclipse.org/downloads/ 找到:eclipse-inst-jre-win64.exe 下载... 2.安装 找到-->Eclipse ... 
- 6.堆和GC
			一. 堆和GC介绍 1.java堆的特点 <深入理解java虚拟机>是怎么描述java堆的 Java堆(Java Heap)是java虚拟机所管理的内存中最大的一块 java堆被所有线程共 ... 
