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. [转]nodejs日期时间插件moment.js

    本文转自:https://blog.csdn.net/dreamer2020/article/details/52278478 问题来源js自带的日期Date可以满足一些基本的需求,例如格式化.时间戳 ...

  2. vs2017和vs2019专业版和企业版

    步骤:打开vs2017,依次点击--->帮助----->注册产品 专业版: Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH 企业版: Enterpr ...

  3. ASP.NET应用程序服务器集群方案

    本文采用Nginx来实现ASP.NET程序集群化. 准备环境 首先准备Nginx环境,Windows版本下载链接:http://nginx.org/en/download.html 解压后文件格式如下 ...

  4. WPF 水印TextBox WatermarkTextBox

    //https://blog.csdn.net/puchitomato/article/details/12248691 转自以上链接,自己添加了Enter响应事件.    public class ...

  5. EF 查询视图出现重复数据

    解决方案: 由多张表组成的视图,要加实体键.而且实体键组合要能确保唯一性. 个人理解:确保唯一性,一个或多个实体键,实现了复合主键或组合主键的效果. 这样查询是,延迟加载机制,才知道哪些需要重新从数据 ...

  6. 正确启动从GitHub上下载的vue项目:vueAdmin-template

    先讲重点,后上相关资料: 遇到的问题:在启动从GitHub上下载的vue项目:vueAdmin-template 时报错:'webpack-dev-server' 不是内部或外部命令,也不是可运行的程 ...

  7. 3Delight NSI: A Streamable Render API

    3Delight是应用于高端电影级别渲染的软件渲染器,迄今为止已经参与了无数的电影制作,具体可以参见链接. 如果你对3Delight的印象就依然是RenderMan的替代品,那就显然已经和时代发展脱节 ...

  8. Nginx设置Https反向代理,指向Docker Gitlab11.3.9 Https服务

    目录 目录 1.GitLab11.3.9的安装 2.域名在阿里云托管,申请免费的1年证书 3.Gitlab 的 https 配置 4.Nginx 配置 https,反向代理指向 Gitlab 配置 目 ...

  9. 基于 libevent 开源框架实现的 web 服务器

    /* 原创文章 转载请附上原链接: https://www.cnblogs.com/jiujue/p/10707153.html   */ 自己实现的如有缺漏欢迎提出 直接代码 一切皆在代码中 首先是 ...

  10. delphi中WMI的使用(网卡是否接入)

    WMI(Windows Management Instrumentation,Windows 管理规范)是一项核心的 Windows 管理技术:用户可以使用 WMI 管理本地和远程计算机. 通过使用W ...