Codeforces Round #102 (Div. 2) 题解
A.
解一个方程。
还是厚颜无耻地暴力吧~
#include <iostream>
using namespace std; int r1, r2, c1, c2, d1, d2;
bool chk(int x1, int x2, int x3, int x4)
{
int ok = 1;
if(x1 == x2 || x1 == x3 || x1 == x4 || x2 == x3 || x2==x4 || x3==x4) ok = 0;
if(x1 + x2 != r1) ok = 0;
if(x3 + x4 != r2) ok = 0;
if(x1 + x3 != c1) ok = 0;
if(x2 + x4 != c2) ok = 0;
if(x1 + x4 != d1) ok = 0;
if(x2 + x3 != d2) ok = 0;
return ok;
} int main()
{
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for(int x1=1;x1<=9;x1++)for(int x2=1;x2<=9;x2++)
for(int x3=1;x3<=9;x3++)for(int x4=1;x4<=9;x4++) {
if(chk(x1, x2, x3, x4)) {
cout << x1 << " " << x2 << endl;
cout << x3 << " " << x4 << endl;
return 0;
}
}
cout << -1 << endl;
}
B.
可以练一练码力的题。
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
char s[202];int minu = 0, n, dot;
vector<char> v;
void rush() {
if(s[1] == '-') minu = 1;
else return; for(int i=1;i<=n-1;i++) {
s[i] = s[i+1];
}
n --; dot --;
}
int main()
{
scanf("%s", s+1);
n = strlen(s+1);
dot = n+1;
for(int i=1;i<=n;i++)
{
if(s[i] == '.') dot = i;
}
rush();
v.push_back(s[1]);
for(int i=2;i<=min(n, dot+2);i++) {
if((dot - i) % 3 == 0 && dot != i) {
v.push_back(',');
}
v.push_back(s[i]);
}
if(dot == n-1) v.push_back('0');
if(dot == n+1) v.push_back('.'), v.push_back('0'), v.push_back('0');
if(minu) printf("(");
printf("$");
for(int i=0;i<v.size();i++) {
printf("%c", v[i]);
}
if(minu) printf(")");
}
C. 给出X,求Y-X的最大值与最小值。
X = A * B * C [A,B,C皆为正整数]
Y = (A+1) * (B+2) * (C+2) [取名为①式]
题解:
我们可以用sqrt(X)的复杂度枚举A。
展开吧!①式!
然后就会发现。B, C越接近,Y越小。【根据基本不等式得到的】
然后开始枚举B的值。【枚举姿势:从sqrt(X/A)向1枚举B】
#include <cmath>
#include <iostream>
using namespace std;
typedef long long LL;
LL n, minc = 1e15, maxc = -1e15;
void solve(LL a) {
LL t = n / a;
maxc = max(maxc, (a+1)*(t+2)*(LL)3 - n);
LL tmp = (LL)sqrt(t) + 1;
for(LL b = tmp; b >= 1; b--) {
if(t % b == 0) {
minc = min(minc, (a+1)*(b+2)*(t/b+2) - n);
}
} }
int main()
{
cin >> n;
for(LL a = 1; a * a <= n; a ++) {
if(n % a == 0) {
solve(a);
solve(n/a);
}
}
cout << minc << " " << maxc << endl;
}
D.
很有趣的一题!
给一个n * m的棋盘。往上放棋子。
然后往上放棋子。如果一个骑士可以从A跳到B。那么A和B不能同时放棋子。
问最多可以放几个棋子。
思路:
先将棋盘按照国际象棋棋盘的方式染色。【就是黑白交错的那种啦!】
然后发现骑士从黑格子只能跳到白格子。从白格子只能跳到黑格子。
所以我们可以在所有黑格子上放棋子。于是可以放$\frac{(mn+1)}{2}$个棋子
不妨设m <= n
当m=1时,$ans = n$
当m=2时,
ans = n+1 (n为奇数)
ans = n+2 (n%4=2)
构造方法如下:
AABBAABBAA
AABBAABBAA
A表示放置棋子。B表示不放棋子
#include <iostream>
using namespace std;
int n, m; int main()
{
cin >> n >> m;
int ans = (m*n+1)/2;
if(n > m) swap(n, m);
if(n == 1) ans = m;
if(n == 2) {
if(m % 2 == 1) ans = m+1;
if(m % 4 == 2) ans = m+2;
}
cout << ans << endl;
}
Codeforces Round #102 (Div. 2) 题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
随机推荐
- Intellij Idea 用Maven 创建Hibernate 项目
第一步:创建maven项目 2. 3. 4.第三步保存之后进行下一步 到此点击finish maven项目创建成功,点击完成后会进行一系列jar包的下载 maven 仓库的默认存储位置 第二步:连接数 ...
- jquery实现图片上传前本地预览
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- ue4构建光照失败问题与解决
不知从哪天开始,我的ue4.13就突然无法成功构建光照了, 症状为:虽然swarm连接到了100%,然而之后就卡住一动不动,一看看log是连接tcp什么agent什么失败的. 虽然把所有物体都设置成非 ...
- linux重要的守护进程
重要的守护进程 守护进程(Daemon)通常会随系统启动时激活并随系统关闭时停止,一直在系统后台中默默为用户提供服务: 守护进程名称 用处 crond 计划任务 dhcpd 动态IP地址分配服务(DH ...
- WPF 杂谈——入门介绍
对于WPF的技术笔者是又爱又恨.现在WPF的市场并不是很锦气.如果以WPF来吃饭的话,只怕会饿死在街头.同时现在向面WEB开发更是如火冲天.所以如果是新生的话,最好不要以WPF为主.做为选择性来学习一 ...
- HashMap负载因子
下面是HashMap的一个构造函数,两个参数initialCapacity,loadFactor 这关系HashMap的迭代性能. /** * Constructs an empty <tt&g ...
- AJAX应用案例之省市联动
jsp 主要是要注意多Document的操作 <%-- Created by IntelliJ IDEA. User: YuWenHui Date: 2017/4/23 0023 Time: 1 ...
- FrameBuffer系列 之 一点资源
Iamonlyme的FrameBuffer编程实例http://download.csdn.net/detail/iamonlyme/6512955 light588的通过framebuffer直接写 ...
- Xcode8插件安装
一.创建一个自定义证书并且为Xcode重新签名1.打开钥匙串 2.创建自定义签名证书 3.重新签名Xcode(速度比较慢,大概要等1分钟) $ sudo codesign -f -s XcodeSig ...
- 给上传文件的input控件"美容"
作为一名前端程序猿呢,在工作中经常会遇到form表单这种东西.然而表单的其他input控件样式还是很好改变的.但是,唯独input类型是file的文件上传控件可能就没那么好打扮的漂亮.刚好菜鸟我最近工 ...