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. Nginx开启Gzip压缩提高页面加载速度

    本文转自http://www.veryhuo.com/a/view/51706.html,如有侵权,请及时联系转载人删除! 在实际运维中,为了提高web页面的访问加载速度,一般会把静态资源(比如js. ...

  2. 记录下关于SQL server1433端口监听不了的问题

    CMD命令netstat -an |findstr 1433,即使在防火墙的入站规则里添加了1433端口的访问,发现1433的端口还是监听不了. 搞了老半天,最终调整了MSSQESERVER的协议下的 ...

  3. 【Python图像特征的音乐序列生成】第一阶段的任务分配

    从即日起到7月20号,项目成员进行了第一次任务分配. 赵同学A.岳同学.周同学,负责了图像数据的情感数据集制作,他们根据自己的经验,对图像进行了情绪提取. 赵同学B全权负责向量映射这一块的网络搭建. ...

  4. JEECMS开发问题汇总

    1 添加Controller 将controller文件放在com.jeecms.cms.action.front包中, 图1.1 然后在jeecms-servlet-front-action.xml ...

  5. 用python Image读图

    https://www.cnblogs.com/kongzhagen/p/6295925.html import os name = [] with open('/media/hdc/xing/Dee ...

  6. ios sinaweibo 客户端(三)

    这个页面要讲述的是用户的粉丝列表,下面是效果图: 可以看到这个视图明显也是一个tableview,在每一个cell中包含的有三个部分的内容:粉丝头像image,粉丝昵称label,我和粉丝之间的相互关 ...

  7. 关于OnTimer()使用

    OnTimer()其实是用来响应WM_TIMER消息的,其实OnTimer()就是一个回调函数,不过是系统默认的,当用户使用SetTimer()函数设定一个定时器的时候,只要是第三个参数为NULL,则 ...

  8. 预防cdn链接失效,无缝切换本地文件

    如今的前端项目追求的不仅仅是能用能看的程度,而是愈发追求项目的性能,对用户体验的影响.而现在的开发工具在性能优化方面也替我们做很大一部分的工作,想必大家对CDN的使用都是轻车熟路了,但是大家有没有考虑 ...

  9. Boostrap的自适应功能

    其实理解栅栏模式之后,自适应功能就简单很多了,根据浏览器的大小,Boostrap有四种栅栏类名提供使用,用法与Css样式表类名选择器样式调用是一样的: xs:col-xs-1 ~ col-xs-12, ...

  10. Hogan的安装和使用

    Hogan的安装和使用 通过npm安装hogan: npm install hogan.js --save-dev CommonJs下的使用方式: // 引入hogan var hogan = req ...