Codeforces #402

Codeforces 779A Pupils Redistribution

链接:http://codeforces.com/contest/779/problem/A

题意:有A组和B组,每组有n个人,A组里面每个人的分值为\(a_i\),B组里面每个人的分值为\(b_i\),\(1\le a_i ,b_i\le5\),至少双方要交换多少人才能使使A组里面每种分值的人要和B组里面一样多。

思路:如果两个在\(i\)这个分值上面人数之差为奇数,就不行,如果为偶数,假如A比B多,那么要A跟B交换差的一半,如果B的在\(j\)这个分值上面比A多,那么刚好就可以跟\(i\)这个分值的交换,所以答案就是他们之间差的一半。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
int cnta[10],cntb[10];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
memset(cnta,0,sizeof(cnta));
memset(cntb,0,sizeof(cntb));
int x;
for(int i=1;i<=n;i++){
scanf("%d",&x);
cnta[x]++;
}
for(int i=1;i<=n;i++){
scanf("%d",&x);
cntb[x]++;
}
bool flag=true;
int cnt=0;
for(int i=1;i<=5;i++){
int num=abs(cnta[i]-cntb[i]);
if(num>0){
if(num%2==1) {
flag=false;
break;
}
else cnt+=num/2;
}
}
if(flag){
printf("%d\n",cnt/2);
}
else {
printf("-1\n");
} }
}

Codeforces 779B Weird Rounding

链接:http://codeforces.com/contest/779/problem/B

题意:有两个数\(n,k\),最少要删掉\(n\)里面多少个数字,才能使得\(n\)整除\(10^k\)。30020如果删掉2就为3000,如果为1000,删掉1,为000,全部删掉为0,有多个0要删到只剩1个0才算0。

思路:贪心,肯定是从后面开始删,每次删完判断一次,不行继续,如果删到只剩下0了但是不止一个0,这个时候就可以直接删掉当前数的位数-1就只剩下一个0了。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
int a[20];
int cnt;
long long mod;
void change(long long tmp){
cnt=0;
while(tmp){
a[cnt++]=tmp%10;
tmp/=10;
}
}
long long changenum(int num[],int len){
long long tmp=0;
long long dig=1;
for(int i=0;i<len;i++){
tmp+=num[i]*dig;
dig*=10;
}
return tmp;
}
int ans;
int main(){
long long num;
int k;
while(scanf("%I64d",&num)!=EOF){
scanf("%d",&k);
mod=1;
for(int i=1;i<=k;i++){
mod*=10;
}
ans=0;
if(num%mod==0) {
printf("0\n");
continue;
}
else {
bool flag=false;
while(!flag){
if(num==0&&cnt!=1){
ans+=(cnt-2);
}
if(num%mod==0){
flag=true;
break;
}
change(num);
for(int i=0;i<cnt;i++){
if(a[i]!=0){
for(int j=i+1;j<cnt;j++){
a[j-1]=a[j];
}
ans++;
break;
}
}
num=changenum(a,cnt-1); }
printf("%d\n",ans);
}
}
return 0;
}

Codeforces 779C Dishonest Sellers

链接:http://codeforces.com/contest/779/problem/C

题意:有\(n\)个商品,每个商品有个当前价格\(a_i\),和一个星期之后的折扣价格\(b_i\),现在一定要在当前至少买\(k\)个物品,问怎么样购买才能使买完\(n\)个商品花费最低

思路:原价=\(a1+...+a_n\),折后价=\(b_1+...+b_k+...+a_n\),原价-折后价=\(\sum_{i=1}^{k}(a_i-b_i)\),所以要想折后价低,就要选择两者差价尽量大的,也就是差价小的买原价。注意如果当折后价比原价贵,那么就可以直接选择原价。

#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int MAXN=2e5+10;
int n,k;
int a[MAXN],b[MAXN];
bool flag[MAXN];
struct node{
int id;
int num;
};
node c[MAXN];
bool cmp(node a,node b){
return a.num<b.num;
}
int main(){
while(scanf("%d %d",&n,&k)!=EOF){
memset(flag,false,sizeof(flag));
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%d",&b[i]);
}
for(int i=1;i<=n;i++){
c[i].num=a[i]-b[i];
c[i].id=i;
if(c[i].num<=0) flag[c[i].id]=true;
}
sort(c+1,c+1+n,cmp);
long long ans=0;
for(int i=1;i<=k;i++) flag[c[i].id]=true;
for(int i=1;i<=n;i++){
if(!flag[i]) ans+=b[i];
else ans+=a[i];
}
printf("%lld\n",ans);
}
return 0;
}

Codeforces 779D String Game

链接:http://codeforces.com/contest/779/problem/D

题意:现在有一个字符串原串\(t\),有一个模式串\(p\),现在保证在原串里面删除一些字母,\(p\)仍然存在于\(t\)里面(子序列),给出删除的顺序\(a_i\),问最多能删到哪一步\(p\)里面还包含\(t\)。

思路:二分答案,O(n)判定子序列

Codeforces #402的更多相关文章

  1. codeforces 402 D. Upgrading Array(数论+贪心)

    题目链接:http://codeforces.com/contest/402/problem/D 题意:给出一个a串和素数串b .f(1) = 0; p为s的最小素因子如果p不属于b , 否则 . a ...

  2. CodeForces 402 E Strictly Positive Matrix

    Strictly Positive Matrix 题解: 如果原来的 a[i][j] = 0, 现要 a[i][j] = 1, 那么等于 sum{a[i][k] + a[k][j]} > 1. ...

  3. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  4. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  5. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  6. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  7. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

  8. Diary of Codeforces Round #402 (Div. 2)

    这一场的表现可以用"全程智障"4个字,生动传神地描述出来. About 写题: A. 写了一堆if比较大小, 这很勤勉.(绝对值君对自己の存在感为0表示很难过.) B. 题,直接读 ...

  9. http://codeforces.com/contest/402/problem/E

    E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. Map集合。

    Map集合: java.util,Map<k,v> 特点:1.键值对 2.key-value一一对应 3.key不允许重复. Map常用实现类: java.util.HashMap< ...

  2. 从零开始学安全(四十四)●TCP三次握手四次挥手

    wireshark:Beyond Compare是一个网络封包分析软件.网络封包分析软件的功能是撷取网络封包,并尽可能显示出最为详细的网络封包资料.Wireshark使用WinPCAP作为接口,直接与 ...

  3. 如何利用GitHub设计一个炫酷的个人网站(含代码)

    1.在开始制作之前我们先预览一下我的网站吧! 1.方式一: 由于是手机版的所以用手机访问下面的链接体验比较好一点: https://tom-shushu.github.io/MyWeb.github. ...

  4. Vue 单选框与单选框组 组件

    radio组件 v-model  : 通过当然绑定的值与input上的value值来确定当前选中项. 在父作用域中通过active设置当前默认选中项,如果选中项发生改变后通过input事件通知传递到父 ...

  5. c#调用word文件

    大家好!我叫蓝颜,我是一名大专生.这是我第一次接触博客园,以后也会一直在. 在学校期间,参加技能大赛(物联网),接触到的C#.之后学校教务处要一个调课软件, 于是我就小试牛刀试了试.当然了,这也是我第 ...

  6. java:数据结构(二)栈的应用(进制转换全收集)

    说到进制转换,java已经封装了基本的方法,在竞赛中使用封装的方法自然能节省大量时间 另一位仁兄介绍的封装好的方法: https://blog.csdn.net/m0_37961948/article ...

  7. 深入理解group by 语句的执行顺序 from→where→group by→select(含聚合函数)

    由于之前没有对group by 语句的执行顺序(执行原理)做深入的了解,所以导致在实际应用过程中出现了一些问题.举个简单的粟子,比如一个表testA中的所有数据如下图: 我现在想从testA中查询us ...

  8. Python之python的一些理解

    应用领域: 1. 网络爬虫 2. 大数据分析与挖掘 3. 机器学习 4. web应用 5. 游戏开发 6. 自动化运维 入门学习网站: imooc,廖雪峰,黑马 环境变量 --- 就是告诉电脑,你的程 ...

  9. 用css 添加手状样式,鼠标移上去变小手,变小手

    用css 添加手状样式,鼠标移上去变小手,变小手 cursor:pointer; 用JS使鼠标变小手onmouseover(鼠标越过的时候) onmouseover="this.style. ...

  10. DC/OS安装

    dc/os: https://dcos.io/ 安装文档-docker:https://docs.mesosphere.com/1.11/installing/oss/custom/system-re ...