101 Hack 50 闲来无事。也静不下心,打个代码压压压惊

Hard Questions

Vincent and Catherine are classmates who just took an exam in Math 55. The exam consists of  multiple-choice questions. Each question has  choices, each of which is represented by a single capital letter ABCD and E. Each question has exactly one correct answer. A student's score is equal to the number of questions he/she correctly answered.

This was the hardest exam they've ever taken! No one was ever sure of their answer even after the exam, and some students weren't even able to answer all the questions. The questions were so hard that Vincent and Catherine strongly believe that they can't both be correct in any question. In other words, for each question, they believe that one or both of them must be incorrect.

Now, Vincent wants to know how well he could have performed in the exam. Given the answers of Vincent and Catherine, find the maximum score that Vincent could have gotten, assuming that they can't both have gotten the correct answer to any particular question.

Input Format

The first line contains a single integer , the number of questions. 
The second line contains a string of length  denoting the answers of Vincent. 
The third line contains a string of length  denoting the answers of Catherine.

Each answer string consists of only the characters ABCDE and . (dot character).

  • If the 'th character is ABCD or E, then this character represents the student's answer for the 'th question.
  • If the 'th character is ., then this means the student gave no answer for the 'th question.

Constraints

 

Output Format

Print a single line containing a single integer denoting the maximum score that Vincent could have gotten assuming that they can't both have gotten the correct answer to any particular question.

Sample Input 0

24
CCACCBAEBAAAAAAAA.......
CCACCBAEBAAAAAAAA.......

Sample Output 0

0

Explanation 0

In this case, Vincent and Catherine answered exactly the same for the whole exam. Since they can't both be correct in any question, it means they are both incorrect in every question. Hence, they both score .

Sample Input 1

7
ACCEDED
DECADE.

Sample Output 1

4

Explanation 1

In this case, the answer sheet could have been ACBEABD, in which Vincent scores . However, one can also show that Vincent cannot get a higher score than  assuming Vincent and Catherine can't both be correct in any question. Hence, the answer is .

The following diagram illustrates this case:

Sample Input 2

11
BEE..ADDED.
CAB.DAD.DEE

Sample Output 2

6

Explanation 2

In this case, the answer sheet could have been BEEADEBDEDE, in which Vincent scores . However, one can also show that Vincent cannot get a higher score than  assuming Vincent and Catherine can't both be correct in any question. Hence, the answer is .

The following diagram illustrates this case:

 

这是一道难(简单)题,有两个人在做一个数学测试,因为太难两个人不可能都做对,如果是"."就说明他没做,所以要你贪心下第一个人最多可以对几个

这种题可以拿来锻炼英语,做起来是没什么价值的,就是两个人不一样,而且不是“.”呗

#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie();cout.tie();
int n;
cin>>n;
string s,c;
cin>>s>>c;
int f=;
for(int i=;i<n;i++)
if(s[i]!=c[i]&&s[i]!='.')
f++;
cout<<f;
return ;
}

Even-odd Boxes

Lucy has an array of  boxes. The boxes are arranged in a straight line numbered  to  from left to right. Box  contains  chocolates.

Lucy thinks the arrangement looks beautiful if the boxes follow an even-odd repetitive pattern. That means the first box contains an even number of chocolates, the second box contains an odd number, the third box contains even, and so on. Here's a beautiful even-odd arrangement:

Lucy is asking you to make beautiful even-odd arrangements from her arrays of boxes. You are allowed to move some chocolates from one box to another. But you are not allowed to swap the boxes. In the final arrangement, every box must contain at least one chocolate.

Calculate the minimum number of chocolates you need to move to get an even-odd repetitive pattern. If it's not possible to get the desired pattern, print -1.

Input Format

The first line contains an integer  denoting the number of queries. 
The first line of each query contains an integer  denoting the number of boxes. 
The second line of each query contains  space-separated integers  describing the number of chocolates in each box.

Constraints

Subtask

  • for  of the maximum score

Output Format

Print an integer describing the minimum number of chocolates you need to transfer to get the even-odd repetitive pattern. If it's not possible to get the desired pattern, print .

Sample Input 0

3
6
6 8 3 1 1 4
5
3 1 1 1 1
3
14 3 10

Sample Output 0

2
-1
0

Explanation 0

  • Query :

We have to transfer two chocolates to maintain the pattern. One possible way to transfer chocolates is shown below.

  • Query :

We can only transfer one chocolate from the first box. No matter what we do, we cannot get the even-odd pattern.

  • Query :

The boxes are already in the even-odd pattern so we don't need to transfer any chocolate.

 
最近也做了不少这样的题,都是奇偶分析,所以我想这个题可以我用模拟方法跑一下,大概也是O(n),但是是有些情况没有考虑到的
所以八一八大神的做法好了。找来一个选手的代码进行思路研究。
先找到1的个数one非1的个数remenan,然后求下容器的累加和。
1因为不允许0个所以sum有最小值
2sum要和n的奇偶性一致
这个求得最小的最小转换是很巧妙的,就是让他变成一个
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);cin.tie();cout.tie();
int T;
cin>>T;
while(T--){
int n;
cin>>n;
vector<int> a(n);
for(int i=;i<n;i++) cin>>a[i];
int one=,rem=;
for(int i=;i<n;i++)if(a[i]%!=i%){
if(a[i]==) ++one;
else ++rem;
}
int ok=;
ll sum=accumulate(a.begin(),a.end(),0ll);
if(sum%!=n*(n-1ll)/%) ok=;
if(sum<n/+(n+)/*) ok=;
cout<<(ok?one+max(,rem-one)/:-)<<endl;
}
return ;
}
 
 

101 Hack 50的更多相关文章

  1. 101 Hack October'14

    拖了近一个月的总结.(可能源于最近不太想做事:() A题 给出n个长度都为n的字符串,你只可以对每个字符串分别排序,问当每个字符串按升序排序之后,每一列是否也是升序的. #include <cm ...

  2. 一次不成功的脚本Hack[捕鱼达人游戏]

    捕鱼达人这款游戏[http://keleyi.com/game/1/] 想当然的以为在这个id为“fishContainer”的div上绑定一个点击事件,子弹就可以快速的发射. 为此用油猴挂载了一个j ...

  3. bench.sh 跑分测速

    #!/bin/bash #==============================================================# # Description: bench te ...

  4. .NET entityframework for mysql ,datetime字段存储值时有误差

    昨天Tester发现数据有问题,大部分时间“datetime类型”都多了一秒,很少一部分数据的时间能完全对上(年月日时分秒),因为缺少关键日志,就各种排查,最后发现在调用Savechange方法前一刻 ...

  5. Python入门学习笔记

    了解 一下Python中的基本语法,发现挺不适应的,例如变量经常想去指定类型或者if加个括号之类的.这是在MOOC中学习到的知识中一点简单的笔记. Python的变量和数据类型: 1.Python这种 ...

  6. #linux包之tcpdump之tcpdump命令

    概述 man tcpdump 已阅 yum install tcpdump Downloading Packages:(1/2): libpcap-1.4.0-1.20130826git2dbcaa1 ...

  7. sql语句小练习二

    1.创建一个数据库StudentManage, 初始化大小10M,不足以1M每次增长 create database StudentManage   on ( name = 'StudentManag ...

  8. [转载] FFmpeg API 变更记录

    最近一两年内FFmpeg项目发展的速度很快,本来是一件好事.但是随之而来的问题就是其API(接口函数)一直在发生变动.这么一来基于旧一点版本的FFmpeg的程序的代码在最新的类库上可能就跑不通了. 例 ...

  9. 部分常见ORACLE面试题以及SQL注意事项

    部分常见ORACLE面试题以及SQL注意事项 一.表的创建: 一个通过单列外键联系起父表和子表的简单例子如下: CREATE TABLE parent(id INT NOT NULL, PRIMARY ...

随机推荐

  1. pt-table-checksum和pt-table-sync

    环境:系统bsd,标准安装,ports安装的mysql. 主172.16.21.126 从172.16.21.128vi /etc/rc.conf 添加 mysql_enable="YES& ...

  2. 宿主机Windows访问虚拟机Linux文件(一)

    如果用户使用windows操作系统,但是在虚拟机下配置Linux内核操作操作系统,往往需要实现通过宿主机Windows操作系统访问Linux内核操作系统中资源.本次实验实现的是宿主机windows 1 ...

  3. Windows环境中,通过Charles工具,抓取安卓手机、苹果手机中APP应用的http、https请求包信息

    Windows环境中,通过Charles工具,抓取安卓手机.苹果手机中APP应用的http.https请求包信息1.抓取安卓手机中APP应用的http请求包信息1)在电脑上操作,查看Windows机器 ...

  4. c#在不安装Oracle客户端的情况下与服务器上的Oracle数据库交互

     概述:     C#通过使用ADO的方式在未安装Oracle数据库的前提下,客户端程序远程访问服务器,会出现:“System.Data.OracleClient 需要 Oracle 客户端软件 8. ...

  5. sudo的用法

    为了系统安全我们一般不直接使用root用户进行日常维护,sudo是临时提升root权限,有时执行一些命令或者更新没权限的文件时需要使用root,这个时候就需要sudo上场了 普通用户是没有sudo使用 ...

  6. AutoHotKey设置ide的光标功能键

    CapsLock:: SetCapsLockState,off ;锁定为小写 CapsLock & d:: flag_C=1 ;小写d代替control键,实现跨词移动CapsLock &am ...

  7. Android(java)学习笔记129:对ListView等列表组件中数据进行增、删、改操作

    1. ListView介绍 解决大量的相似的数据显示问题 采用了MVC模式: M: model (数据模型) V:  view  (显示的视图) C: controller 控制器 入门案例: aci ...

  8. python_89_configparser模块

    用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser.在python2.x版本中为ConfigPsresr 来看一个好多软件的常见文档格式如下 [ ...

  9. cocos2dx for lua A*寻路算法实现2

    关于A*算法的实现过程,简单来说就是一个计算权限的过程. 首先,创建一个地图节点类,"MapNode.lua" local MapNode = class("MapNod ...

  10. wsl基本安装与配置

    wsl简介: Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层.它是由微软与Canoni ...