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, ...
随机推荐
- logstash-input-jdbc 同时同步多个表的情况
input { jdbc { jdbc_connection_string => "jdbc:mysql://localhost:3306/crm?zeroDateTimeBehavi ...
- 做一个U盘的学习路线
最近想研究一个U盘,然后顺便熟悉一下USB协议.因为USB协议比较复杂, 常用的复杂外设除了WiFi,Ethernet,SDIO和USB这些就是USB了,学习USB的时候肯定要拿一个东西下手,所以简单 ...
- 学习PHP弱引用的知识
之前的文章中,我们已经学习过引用和引用传值相关的知识.我们知道,PHP 中没有纯引用(指针),不管是对象,还是用引用符号 & 赋值的变量,都是对一个符号表的引用.而今天,我们要学习的是另一种引 ...
- nginx使用用户真实IP做hash(解决经过CND后ip_hash失效问题)
在nginx中常用的有以下四种负载均衡的算法,分别是:round-robin.ip-hash.least-connected和weighted.当然在实际生产中或许使用最多的就是ip-hash了,一般 ...
- P5445-[APIO2019]路灯【set,树状数组套线段树】
正题 题目链接:https://www.luogu.com.cn/problem/P5445 题目大意 \(n+1\)个点,\(i\)和\(i+1\)个点之间有一条边,\(q\)个操作 断开/连接第\ ...
- PYTHON django 关于时间转换
在安装django.默认会pytz时区库,import pytzpytz.timezone("UTC")now.astimezone("要转换的aware类型" ...
- GitHub 和 Gitee 开源免费 10 个超赞后台管理面板,看完惊呆了!
软件工程师在实际项目开发中不可避免需要依赖一些前后端的后台管理系统框架,而不是从零开始一点点的搭建,浪费人力.目前市面上有很多开放源码.且免费的后台管理面板,样式色彩也比较丰富美观. 今天整理 ...
- pycharm中安装扩展包
在使用Pycharm编写代码时,如果遇到了所需要的扩展包没有的情况时,可以使用以下方法来添加自己需要的扩展包. 1.点击File->settings 2.选择Project Interprete ...
- DIVIDEMIX: LEARNING WITH NOISY LABELS AS SEMI-SUPERVISED LEARNING
论文阅读: DIVIDEMIX: LEARNING WITH NOISY LABELS AS SEMI-SUPERVISED LEARNING 作者说明 版权声明:本文为博主原创文章,遵循CC 4.0 ...
- vue使用AES.js
AES加密的使用 对数据传输加密.解密处理---AES.js 第一步: 在vue中安装crypto-js依赖 npm install crypto-js --save-dev 第二步: 在static ...