题目链接

我怎么连这种题都做得那么艰难……

可以发现一些结论,然后枚举'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 | 贪心的更多相关文章

  1. CodeForces - 777B Game of Credit Cards 贪心

    题目链接: http://codeforces.com/problemset/problem/777/B 题目大意: A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并 ...

  2. Game of Credit Cards(贪心+思维)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  3. Cards and Joy CodeForces - 999F (贪心+set)

    There are nn players sitting at the card table. Each player has a favorite number. The favorite numb ...

  4. Codeforces 777B:Game of Credit Cards(贪心)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  5. 【贪心】【multiset】 Codeforces Round #401 (Div. 2) B. Game of Credit Cards

    对第一个人的排序,然后从小到大处理,对第一个人的每枚卡片,从第二个人的卡片中选择一个大于等于它的最小的,否则选择一个当前剩下的最小的,这样可以保证负场最少. 如果选择的改成大于它的最小的,就可以保证胜 ...

  6. 【Yellow Cards CodeForces - 1215A 】【贪心】

    该题难点在于求最小的离开数,最大的没什么好说的,关键是求最小的. 可以这样去想,最小的离开数就是每个人获得的牌数等于他所能接受的最大牌数-1,这样就可以直接比较m=a1(k1-1)+a2(k2-1)与 ...

  7. NUC_TeamTEST_B(贪心)

    B - B Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  8. Alice and Bob(贪心HDU 4268)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. HDU4268 Alice and Bob(贪心+multiset)

    Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...

随机推荐

  1. [源码解析] 深度学习分布式训练框架 horovod (20) --- Elastic Training Operator

    [源码解析] 深度学习分布式训练框架 horovod (20) --- Elastic Training Operator 目录 [源码解析] 深度学习分布式训练框架 horovod (20) --- ...

  2. EditPlus配置C/C++运行环境

    1.安装MinGW和EditPlus 2.打开EditPlus ctrl+1 编译 ctrl+2 运行

  3. 【OI】C++STL 不定长数组 vector

    Vector 本来是向量的意思,只不过在用法上类似于一个不限长度的数组. 定义语法:vector<数据类型> 名称; 一.头文件:<vector> (bits/stdc++请忽 ...

  4. 性能再提升70%?大咖前瞻带你揭开.NET6的神秘面纱!

    本月初微软官宣.NET 6 的RC1即将在11月正式发布,这意味着.NET6正式版跟我们见面的时间又近了一步.在之前的.NET6预览版本中,微软加入了大量新功能特性,而在最终版本中将不再额外加入新的内 ...

  5. flex 简单设置

    /*弹性盒子 start*/ /* ============================================================ flex:定义布局为盒模型 flex-v: ...

  6. ecshop调用商品的购买次数方法

    这时候我们修改一下 写成一个函数放到lib_goods.php 这样就可以随便调用了 --------------------------------------------------------- ...

  7. Roslyn(CSharpScript).Net脚本编译引擎使用过程内存增涨与稳定的方式

    目       录 1.      引用程序集... 1 2.      内存增涨的情况... 2 3.      内存稳定的情况... 4 1.   引用程序集 Roslyn 是微软公司开源的 .N ...

  8. 做PPT总是很难找到好看、有质感的图片,怎么办?

    1.制作PPT时,要想提升整体质感,就需要插入一些图片.当你进入到这个阶段,就意味着你剩下用来做PPT的时间,可能比较紧张了.所以,你的重中之重是,在最短的时间内找到合适的照片. 2.想快速找到好看. ...

  9. lua文件修改为二进制文件

    注意:lua编译跟luajit编译的二进制文件是不兼容,不能运行的 如果是使用luajit,请直接使用luajit直接编译二进制 第一种:luajit编译(以openresty为例,跟luac是相反的 ...

  10. nginx负载轮询

    下面是一个可以使用nginx负载轮询,如果有一台服务器连接不通,返404,500,502,503,504,会自动切换到下一台服务器 upstream www { server 111.111.111. ...