#316 div.2
主要记录下被坑的B。果然大晚上脑子就是不知道在干嘛,明明都测到 “1 1” 这个样例错了都没发现直接给放过去了,白白让人hack爽了...
题意就是给你一个数m,让你从1~n个数中选一个作a,使1~n中的任意选一个数c,满足|c-m| > |c-a|的可能性最大,也就是离m近的数比离a近的数多,多种可能输出小的;
画一下草图就能知道算是个几何概率吧,如果m-1 > n-m,即m离1近,那么在m+1~n中选一个位置a都会有更大的可能使离a近的数比离m近的数多;而其中概率最大的就是m+1 -- 只要c>=m+1都会满足|c-a| < |c-m|;
同理m-1 > n-m的情况,选a为m-1能使满足|c-a| < |c-m|的c值最多;
注意1 1应输出1
#include<cstdio>
#include<cstdlib>
#include<cstring>
int main()
{
int n, m;
scanf("%d%d", &n, &m);
if(n == m && n == ) printf("1\n");
else
{
if(n-m > m-)
{
printf("%d\n", m+);
}
else
{
printf("%d\n", m-);
}
}
return ;
}
这场前三都不难,都能秒出,主要还是自己的代码准确度。。。
A题让你选出票数最多的竞选人,
m行n列,aij表示第i个城市分别给第1~j位候选人投了ai1~aij票,选出其中票数最多的就是这个城市选出的候选人,如果票数相同选序号小的;
然后统计m个城市选出的票数最多的候选人,票数相同选择序号小的。
水题不多说了;
C题先给你一个长度为n的字符串,然后进行m种修改操作,每次操作将位置x的字符替换成字符c,然后统计更新字符串中连续两个‘.’的个数(即[..]的个数),注意一旦更新后就保持下去了,不会恢复到初始字符串;
猛一看是个字符串查找,稍微一想不就是个模拟吗,首先计算出把原串中[..]的个数sum。每次操作sum的增减仅跟当前要替换的字符的左右两边相邻的两个字符有关:
1)若 s[x] != ‘.’ 且 c == ‘.’,如果 s[x-1] == ‘.’,那么ans++; 如果s[x+1] == ‘.’,ans++;
2)若 s[x] == ‘.’ 且 c != ‘.’ ,如果 s[x-1] == ‘.’,那么ans--; 如果s[x+1] == ‘.’,ans--;
没有什么坑点,也不上代码了;
#316 div.2的更多相关文章
- Codeforces Round #316 (Div. 2) D. Tree Requests dfs序
D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement set
C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
- Codeforces Round #316 (Div. 2)
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #316 (Div. 2) D、E
Problem D: 题意:给定一棵n个点树,每个点有一个字母,有m个询问,每次询问某个节点x的子树中所有深度为k的点能否组成一个回文串 分析:一堆点能组成回文串当且仅当数量为奇数的字母不多于1个,显 ...
- Codeforces Round #316 (Div. 2C) 570C Replacement
题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...
- Codeforces Round #316 (Div. 2B) 570B Simple Game 贪心
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...
- Codeforces Round #316 (Div. 2A) 570A Elections
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- Windows x86 x64使用SetThreadContext注入shellcode的方式加载DLL
一.前言 注入DLL的方式有很多,在R3就有远程线程CreateRemoteThread.SetWindowsHookEx.QueueUserApc.SetThreadContext 在R0可以使用a ...
- HITAG 2 125kHz RFID IC Read-Write 256 bits
Features 256 bits EEPROM memory organized in 8 pages of 32 bits each 32 bits unique factory programm ...
- CSS实现标题右侧“更多”
HTML < h2>< a h ref="#" >标题< /a> < span>更多…< /span> < /h2 ...
- wpa_supplicant 连接成功后,如何配置wlan0与br0 协调上网
wlan0 地址,路由配置完成后,加入两条iptables 规则. #iptables -A FORWARD -i wlan0 -o br0 -s -m state --state NEW -j AC ...
- js原生appendChild的bug
appendChild 主要是用来追加节点 插入到最后 window.onload = function(){ var ul2 = document.getElementById('ul2'); va ...
- 编写你自己的单点登录(SSO)服务
王昱 yuwang881@gmail.com 博客地址http://yuwang881.blog.sohu.com 摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统其中.本文从 ...
- zTree实现基本树
zTree实现基本树 1.实现源代码 <!DOCTYPE html> <html> <head> <title>zTree实现基本树</title ...
- Android输入输出机制之来龙去脉
openInputChannelPair( 阅读本文的前提条件是知道匿名管道和匿名共享内存是怎么一回事,否则阅读相应的文章. Anonymous pipes 和Anonymous Shared Mem ...
- Lua游戏脚本语言入门(一)
作者: 沐枫 (第二人生成员) 原文地址:http://job.17173.com/content/2009-01-22/20090122143452606,1.shtml 在这篇文章中,我想向大家介 ...
- DB2 重新设定表自增字段的当前值
转自:http://blog.csdn.net/jionghan3855/article/details/2709073 1.ALTER TABLE UKEY_INFO_TAB ALTER COLUM ...