题目链接

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

可以发现一些结论,然后枚举'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. vue-cli3项目中使用vue-ueditor-wrap

    Vue + UEditor + v-model 双向绑定 一.安装 1 npm i vue-ueditor-wrap 2 # 或者 3 yarn add vue-ueditor-wrap 二.下载文件 ...

  2. vue中的watch

    1.第一种 watch:{ total:{ // total:要检测的数据   handler:(val,oldVal)=>{ // handler方法自动执行   }, deep:true / ...

  3. java.lang.SecurityException: MODE_WORLD_READABLE错误解决

    问题描述:运行Android项目有以下报错: 解决方法: 把 MODE_WORLD_READABLE 更换成 MODE_PRIVATE 即可,因为MODE_WORLD_READABLE 模式已经被废弃 ...

  4. CI框架 ::集成极光推送

    分三步 1:引入类: 2:新建Jpush类: 3:修改源码(PHP5.3.3环境)

  5. 【HTML】实战阿里云src页面css模仿基础学习

    实战结果页面gif图片 阿里云src首页模仿完整代码(500行左右) <!DOCTYPE html> <html> <head> <meta charset= ...

  6. P7514-[省选联考2021A/B卷]卡牌游戏【贪心】

    正题 题目链接:https://www.luogu.com.cn/problem/P7514 题目大意 给出\(n\)个卡牌有\(a_i/b_i\),开始都是\(a_i\)朝上,将不超过\(m\)张卡 ...

  7. YbtOJ#723-欧拉之树【莫比乌斯反演,虚树】

    正题 题目链接:http://www.ybtoj.com.cn/contest/121/problem/2 题目大意 给出\(n\)个点的一棵树,每个点有一个权值\(a_i\),求 \[\sum_{i ...

  8. asp.net core 集成swagger ui

    什么是Swagger? 说swagger 之前,我们先说一下OpenApi 规范. OpenApi 是一种和语言无关的用于描述RESTAPIs 接口功能的一种规范,对RESTAPIs 接口的描述包括: ...

  9. Java(15)面向对象之继承

    作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15201615.html 博客主页:https://www.cnblogs.com/testero ...

  10. print spooler LPF 打印机漏洞

    打印机漏洞 该漏洞可以通过创建打印机驱动和端口,实现任意文件写入,用于提权或者写入后门. 打印机调用流程:client通过RPC调用server的spoolsv.exe,spoolsv.exe是sys ...