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) 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. 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 题解 直接 ...

随机推荐

  1. Vuex随笔

    最近在项目中使用到了vuex,但是在配合vue使用时,也还是遇到了不少的问题,最终还是解决了问题,因此写一篇随笔来记录期间遇到的问题吧 项目概要: Vuex中所储存的的状态如下: Vue中:有一个ta ...

  2. text-decoration:underline与字体重叠

    前几天工作遇到了字体与underline下划线重叠的问题,折腾了半天.今天在张鑫旭的博客上找到了几种解决方法分享一下 1 text-decoration-skip:不推荐使用 17年了这个属性支持率依 ...

  3. .NET遇上Docker - 使用Docker Compose组织Ngnix和.NETCore运行

    本文工具准备: Docker for Windows Visual Studio 2015 与 Visual Studio Tools for Docker 或 Visual Studio 2017 ...

  4. FPGA中将十进制数在数码管中显示(verilog版)--二进制转换为BCD码

    这周有朋友问怎样在fpga中用数码管来显示一个十进制数,比如1000.每个数码管上显示一位十进制数.如果用高级语言来分离各位,只需要分别对该数做1000,100,10对应的取商和取余即可分离出千百十个 ...

  5. STM32学习笔记(一)——点亮一个LED

    引言 最近报名了2017全国大学生电子设计竞赛,我们学校是第一次参加这个比赛,由于8/9月份就要比赛了,所以现在准备是比较晚的了,指导老师说只能做控制类的题目了,让我们学习一下STM32单片机,51到 ...

  6. Coordinator节点

    Coordinator节点 Coordinator 节点主要负责segment 的管理和分配.更具体的说,它同通过配置往historical 节点 load 或者 drop  segment .Coo ...

  7. 读《effective C++》2

    条款03:尽可能使用const(Use const whenever possible) 1.const == 奇妙的事 const的一件奇妙的事是,他允许你定义一个约束,(告诉编译器,这是一个“不该 ...

  8. 深入理解MVC

    首先我们来看看MVC架构的示意图:             和访问者交互的是控制层(Controller层),控制器(controller)是同类交互的集合,每一个交互的操作,都对应了一个动作(act ...

  9. ionic打包项目,运行时报错A problem occurred configuring root project 'android'。。。

    运行报错的原因是sdk没有下载完整 解决办法: 1,打开sdk manage.分别下载android support repository.Google play services.google re ...

  10. Json对象和Json字符串之间的转换

    json字符串转json对象,调用parse方法: var b='{"name":"2323","sex":"afasdf&quo ...