题目链接:Codefores 398A Cards
题目大意:给出a和b,表示说有a个“o”的卡和b个“x”的卡,将这a+b个卡片排成一个序列,每连续的k个相同的卡片为一个数,表示k^2,如果是o,则是+k^2,否则-k^2。要求找到一个序列使得最后的结果尽量大。
解题思路:一开始一直想用贪心的思想直接构造出来,后来和小伙伴一人想了一种构造方法,但是又互相推翻了。。。。不过很快就想到了暴力,因为b最多1e5,答案肯定要让o尽量在一起,x尽量分开,这样我们每次拿出一个o的卡片就可以让x被多分成一份,所以枚举x被分成的份数,贪心,尽量让o在一起。
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll a, b, ans, v = 1;
ll solve (ll k) {
ll x = b/k, c = b%k;
ll ans = (a-k+2)*(a-k+2) +(k-2);
ll tmp = c*(x+1)*(x+1) + (k-c)*x*x;
return ans - tmp;
}
void put() {
cout << ans << endl;
ll x = b/v, c = b%v;
bool flag = false;
for (ll i = 1; i < v; i++) {
if (flag) printf("o");
for (ll j = 0; j < x; j++) printf("x");
if (i <= c) printf("x");
flag = true;
}
for (ll i = 0; i < (a-v+2); i++) printf("o");
for (ll i = 0; i < x; i++) printf("x");
printf("\n");
}
int main () {
ans = -INF;
cin >> a >> b;
if (a == 0) {
cout << b*b*(-1) << endl;
for (ll i = 0; i < b; i++) printf("x");
printf("\n");
return 0;
}
for (ll i = 2; i <= a + 1; i++) {
ll t = solve(i);
if (t > ans) {
ans = t; v = i;
}
}
put();
return 0;
}
分享到:
相关推荐
developing and managing a successfull payment cards business
Patch to unlock intel cards having SFP+ vendor locking.
Fun, quick, and easy to study while on the go, Mosby’s Medical Terminology Flash Cards, 3rd Edition provide a great tool for learning and reviewing medical terms. 600 full-color flash cards help ...
Arkham_Cards_2.14.10.apk
Arkham Cards.apk
python名片管理系统源码,适用于新手学习基础python,检验学习成果,以及学习python编程基本思想和规则
ccna考试模拟器flashcards,英文试题
Smart Cards and their Operating Systems - SCard SOFT
1 An Introduction to Smart Cards 2 Smart Card Production Environment 3 Multi-Application Smart Card Platforms and Operating Systems 4 Smart Cards and Security for Mobile Communications 5 Smart Cards ...
Belltech Business Cards Designer Pro是一款专业质量的名片设计和打印软件。 可以让你利用任何旋转文字、方块、圆圈、直线、图像来创造惊人的名片。
BS ISO-IEC 14443-3-2016 Identification cards - Contactless integrated circuit cards - Proximity cards - Part 3 Initialization and anticollision
authentication scheme using smart cards to solve the problems of Lamport scheme. Unfortunately, Hwang and Li’s scheme has some security weaknesses. First, Chan- Chang, Shen- Lin- Hwang and then Chang...
语言:English flashcard +让您制作FlashCard集,并具有简单的研究Meathods。 Flashcard +允许您制作无限的学习集,这是一个交互式研究方法。 Flashcard模式可让您正常研究它们。 但是,召回模式让您拼写并重复问题...
Flashcards for USA states
易语言模块cards.rar 易语言模块cards.rar 易语言模块cards.rar 易语言模块cards.rar 易语言模块cards.rar 易语言模块cards.rar
From Cards to Code How Extreme Programming Re-Embodies Programming as a Collective Practice
ISO/IEC 7816-2 Second edition 2007-10-15 Identification cards — ...⎯ Part 13: Commands for application management in a multi-application environment ⎯ Part 15: Cryptographic information application
CCNA_Flash_Cards_and_Exam_Practice_Pack
deck-of-cards是一款非常炫酷的HTML5扑克牌卡片动画类库。它使用纯js和CSS3来实现洗牌,发牌等功能。在这个效果的演示中,扑克牌使用SVG来制作,共给出了5种功能的演示效果。
Cards Transacton Life Cycle