Codeforces Round #253 (Div. 1) (A, B, C)
Codeforces Round #253 (Div. 1)
A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来。
思路:一共2^10种情况,直接暴力枚举,然后对于每种情况去推断,推断的时候仅仅要两两张牌枚举出来推断就可以。不得不说CF机子真心强大,2秒限制还是能跑10^8
B:给定n个发生概率,求选出当中一些事件,使得正好有一件发生的概率最大。
思路:贪心,从大到小排序概率,然后一个个概率进来推断有没有更大,有就增加该事件,没有就跳过
C:给定n个数字,要求一个个删掉数字,假设数字左边或右边没有数字就不得分,否则得分为min(左边数字,右边数字)。
思路:贪心,考虑两种情况,一种下凹的形状,这样的情况下肯定是由中间的优先拿掉在到两边,对于这样的情况能够用一个栈去维护,每次要入栈前,先把之间拿掉并记录答案,在入栈。
这样处理完了,下凹的形状都没了,图形为先递增后递减形状,这时候答案是固定的了,就是最大的两个值肯定是取不到了,剩下的都能取到。这两部分和加起来就是答案
代码:
A题:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const char c[15] = {'1', '2', '3', '4', '5', 'B', 'Y', 'W', 'G', 'R'};
int n, vis[105][2];
char card[105][5];
int bitcount(int x) {
if (x == 0) return 0;
return bitcount(x>>1) + (x&1);
}
bool judge(int s) {
memset(vis, 0, sizeof(vis));
for (int i = 0; i < 10; i++) {
if (s&(1<<i)) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < 2; k++) {
if (card[j][k] == c[i])
vis[j][k] = 1;
}
}
}
}
for (int i = 0; i < n; i++) {
if (vis[i][0] && vis[i][1]) continue;
for (int j = i + 1; j < n; j++) {
if (strcmp(card[i], card[j]) == 0) continue;
if (vis[j][0] && vis[j][1]) continue;
if (!vis[i][0] && !vis[i][1] && !vis[j][0] && !vis[j][1]) return false;
if (!vis[i][0] && !vis[j][0] && card[i][1] == card[j][1]) return false;
if (!vis[i][1] && !vis[j][1] && card[i][0] == card[j][0]) return false;
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%s", card[i]);
int ans = 10;
for (int i = 0; i < (1<<10); i++) {
if (judge(i)) {
ans = min(ans, bitcount(i));
}
}
printf("%d\n", ans);
return 0;
}
B题:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 105;
int n, save[N], sn;
double p[N], sum;
double cal(int now) {
double ss = sum * (1 - p[now]);
double ans = sum * p[now];
for (int i = 0; i < sn; i++) {
ans += ss / (1 - p[save[i]]) * p[save[i]];
}
return ans;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf", &p[i]);
}
sort(p, p + n);
sn = 1;
save[0] = n - 1;
sum = (1 - p[n - 1]);
double Max = p[n - 1];
for (int i = n - 2; i >= 0; i--) {
double tmp = cal(i);
if (tmp > Max) {
sum *= (1 - p[i]);
Max = tmp;
save[sn++] = i;
}
}
printf("%.12lf\n", Max);
return 0;
}
C题:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 500005;
int n, top;
long long stack[N], x, ans;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
while (top > 0 && stack[top - 1] >= stack[top] && x >= stack[top]) {
ans += min(stack[top - 1], x);
top--;
}
stack[++top] = x;
}
sort(stack + 1, stack + 1 + top);
for (int i = 1; i <= top - 2; i++) {
ans += stack[i];
}
printf("%lld\n", ans);
return 0;
}
Codeforces Round #253 (Div. 1) (A, B, C)的更多相关文章
- Codeforces Round 253 (Div. 2)
layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #253 (Div. 2) D题
题目大意是选出一个其他不选,问问最大概率: 刚开始想到DP:F[I][J][0]:表示从 前I个中选出J个的最大值, 然后对于F[I][J][1]=MAX(F[I-1][J][1],F[I-1][J- ...
- Codeforces Round #219 (Div. 1)(完全)
戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...
- Codeforces Round #545 (Div. 2)(D. Camp Schedule)
题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最 ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...
- Codeforces Round #796 (Div. 2)(A~E题题解)
文章目录 原题链接: A.Cirno's Perfect Bitmasks Classroom 思路 代码 B.Patchouli's Magical Talisman 思路 代码 C.Manipul ...
随机推荐
- 6月19日 NSFileHandle文件类的常用方法
NSFileManager类主要对文件的操作(删除,修改,移动,复制等): NSFileHandle类主要对文件内容进行读取和写入操作 NSFileHandle处理文件的步骤 ...
- 第四天学习内容 if switch for 的练习
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 阿斯钢iojeg9uhweu9erhpu9hyw49
http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...
- 我在使用的Chrome插件
首先本人为一名Android程序员,故下面的很多插件很多都是关于开发辅助相关的.当然还有涉及到其他方面的插件,比如社交,浏览,工具等.以下按照字母排序. 1.AdBlock The most popu ...
- 5款帮助简化的HTML5 Audio开发的Javascript类库
HTML5的audio标签提供了我们方便控制声音的功能,可是使用原生的HTML5来开发声音或者音乐相关的项目仍旧很的麻烦.在今天这篇文章中,我们将介绍5款帮助你简化开发的javascript audi ...
- 关于时间,日期,星期,月份的算法(Java中Calendar的用法)(一)
package cn.outofmemory.codes.Date; import java.util.Calendar; import java.util.Date; public class Ca ...
- MVC3和MVC4中CRUD操作
MVC3中EF实现的CRUD操作 public class HomeController : Controller { // // GET: /Home/ CarModelContainer db = ...
- spring mvc 接受多对象的处置
spring mvc 接受多对象的处理 spring mvc感觉非常好用,尤其是对接收对象參数的自己主动绑定非常简便,但对于同一时候传多个对象时有些困扰. 同一时候项目并没有直接使用spring的fo ...
- Dom4j SAXReader Constructors
Dom4j读取xml:eg1: package xml; import java.io.File; import org.dom4j.DocumentException; import org.dom ...
- Swift - 复杂数据类型说明(数组,字典,结构体,枚举)
1,数组 - Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 var types ...