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. uvm_reg_cbs——寄存器模型(十六)

    当你完成寄存器模型的时候,你就会想到给后来的人一个接口,给他更多的扩展,让他做更多的事,一般而言,只有做VIP时,会想到做callbacks. typedef class uvm_reg; typed ...

  2. jquery获取当前被选择的复选框的value的集合

    1.HTML代码 <input type="checkbox" name="productID" value="0"> < ...

  3. SQL Server扩展事件system_health会话总结

    system_health会话概念 我们知道扩展事件(Extended Events)是从SQL Server 2008开始引入的.system_health会话是SQL Server默认包含的扩展事 ...

  4. LoadRunner使用(1)

    一.LoadRunner脚本录制 LoadRunner测试分为两个步骤: 第一步:录制脚本,其实就是监控并记录这段时间发送的HTTP请求 第二步:启动多个线程,用录制的脚本,模拟多线程发送请求. (1 ...

  5. C#中静态成员和实例变量

    昨天晚上看静态成员和实例变量的时候,看到这样的一句话:默认情况下,若成员被定义为实例变量,这就意味着类需要为每个实例都建立一个副本,而在定义一个静态变量的时候,只存在此成员的一个副本. 呵呵,今天跟前 ...

  6. CentOS-语言设置

    查看所有的locale语言 # locale -a # locale -a|grep en 查看当前操作系统使用的语言 # echo $LANG 设置系统locale语言为中文环境(永久生效) # v ...

  7. package.json相关疑惑总结

    语义版本控制(node-semver) X.Y.Z,主要版本X,次要版本Y,补丁Z X:代表一个破坏兼容性的大变化: Y:表示不会破坏任何内容的新功能: Z:表示不会破坏任何内容的错误修复: pack ...

  8. CDOJ 490 UESTC 490 Swap Game(思路,逆序对)

    题意:有两种颜色的小球形成环,求最小交互次数使球相连. 题解:先解决另一个简单的问题,如果是一个链,把红球标记为1,蓝球标记为0,要排成升序需要多少次交换呢?答案是逆序对总数,原因是一次交互最多消除一 ...

  9. 使用EventLog组件保存Windows系统日志

    实现效果: 知识运用: EventLog类的CreateEventSource方法 //用于建立一个应用程序  使用指定的Sourc作为向本机上的日志中写入日志项的有效事件源 CreateEventS ...

  10. Java微信公众号开发----关键字自动回复消息

    在配置好开发者配置后,本人第一个想要实现的是自动回复消息的功能,说明以下几点: 1. url 仍然不变,还是开发配置里的url 2. 微信采用 xml 格式传输数据 3.微信服务器传给我们的参数主要有 ...