F - Debate CodeForces - 1070F 思维
题目链接:https://vjudge.net/problem/CodeForces-1070F
具体思路:首先把所有的00放进去,然后对于10 和01 的取两个数目最小值t,排完序后将前t个加起来,然后再将剩余的看作一类,求一个最大加的数目就可以了。
关于为什么看作一类,第一个原因,剩下的的构成只能是只有00 ,或者(00,10)或者(01,00)或者(10)或者(01),这样就好分清楚剩下的最多加多少了,因为如果放入剩下的话,只能增加一种或者增加两种,所以取最大满足情况的前k项加起来就可以了。
AC代码:
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<stdio.h>
using namespace std;
# define inf 0x3f3f3f3f
# define ll long long
# define maxn 500000+100
int a1[maxn],a2[maxn],aa[maxn],ff[maxn];
int tot[maxn];
bool cmp(int t1,int t2)
{
return t1>t2;
}
int main()
{
int n;
scanf("%d",&n);
int t1,t2;
int num1=0,num2=0,num3=0,num4=0;
for(int i=1; i<=n; i++)
{
scanf("%d %d",&t1,&t2);
if(t1==11)
{
aa[++num1]=t2;
}
else if(t1==10)
{
a1[++num2]=t2;
}
else if(t1==1)
{
a2[++num3]=t2;
}
else if(t1==0)
{
ff[++num4]=t2;
}
}
sort(a1+1,a1+num2+1,cmp);
sort(a2+1,a2+num3+1,cmp);
sort(ff+1,ff+num4+1,cmp);
int sum=0;
int m=0;
int p1=0,p2=0;
int temp=min(num2,num3);
for(int i=1; i<=num1; i++)
{
sum+=aa[i];
}
m+=num1;
p1+=num1;
p2+=num1;
for(int i=1; i<=temp; i++)
{
sum+=a1[i];
sum+=a2[i];
}
m+=temp*2;
p1+=temp;
p2+=temp;
int num=0;
for(int i=temp+1; i<=num2; i++)
{
tot[++num]=a1[i];
}
for(int i=temp+1; i<=num3; i++)
{
tot[++num]=a2[i];
}
for(int i=1; i<=num4; i++)
{
tot[++num]=ff[i];
}
sort(tot+1,tot+num+1,cmp);
int t=min(min(min(p1*2-m,p2*2-m),m),num);//取可加的数目
for(int i=1; i<=t; i++)
{
sum+=tot[i];
}
printf("%d\n",sum);
return 0;
}
以后打组队赛得抓紧了,不能松懈,也尽量少和别的队交流,,,继续加油吧
F - Debate CodeForces - 1070F 思维的更多相关文章
- Debate CodeForces - 1070F (贪心)
Elections in Berland are coming. There are only two candidates — Alice and Bob. The main Berland TV ...
- codeforces 876 F. High Cry(思维)
题目链接:http://codeforces.com/contest/876/problem/F 题解:一道简单的思维题,知道最多一共有n*(n+1)/2种组合,不用直接找答案直接用总的组合数减去不符 ...
- Codeforces Round #548 (Div. 2) F splay(新坑) + 思维
https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\), ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) F. High Cry(思维 统计)
F. High Cry time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Queue CodeForces - 353D (思维dp)
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- newcoder F石头剪刀布(DFS + 思维)题解
题意:wzms 今年举办了一场剪刀石头布大赛,bleaves 被选为负责人. 比赛共有 2n 个人参加, 分为 n 轮, 在每轮中,第 1 位选手和第 2 位选手对战,胜者作为新的第 1 位选手, 第 ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
随机推荐
- sharepoint content type publishing
1. Create 1 Project Team sites (Site1) on SharePoint(可以用普通site)2. Go to http://<PCName>:8080/_ ...
- SQL入门之查询入门
select语法一般结构: SELECT [ALL|DISTINCT] <目标列表达式> [别名] [, <目标列表达式> [别名]]... FROM <表名或视图名&g ...
- HDU4675_GCD of Sequence
很有意思的一个数论题. 是这样的,给你一个数数组a[i],其中给出的每一个数字和要求的数字方位都是[1,m],现在问你根据a[]构造一个b[],且a和b中间的不相等的元素的个数恰好有k个. 现在问你g ...
- 洛谷P3601签到题(欧拉函数)
题目背景 这是一道签到题! 建议做题之前仔细阅读数据范围! 题目描述 我们定义一个函数:qiandao(x)为小于等于x的数中与x不互质的数的个数. 这题作为签到题,给出l和r,要求求. 输入输出格式 ...
- [二]SpringBoot 之 简单的接口
(1)编写一个实体类Demo package me.shijunjie.entity; public class Demo { private long id; private String name ...
- Java发送http get/post请求,调用接口/方法
由于项目中要用,所以找了一些资料,整理下来. GitHub地址: https://github.com/iamyong 转自:http://blog.csdn.net/capmiachael/a ...
- ssh后台执行
1 执行scp命令,开始传输2 scp传输开始后,用ctrl+z,再以bg命令将其转入后台运行. 3以exit命令安全退出即可令scp继续执行,不受关闭shell的影响.
- mysql允许远程特定ip访问
1.登录 mysql -u root -p 之后输入密码进行登陆 2.权限设置及说明 2.1添加远程ip访问权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.1 ...
- 【树状数组】【P3902】 递增
传送门 Description 给你一个长度为\(n\)的整数数列,要求修改最少的数字使得数列单调递增 Input 第一行为\(n\) 第二行\(n\)个数代表数列 Output 输出一行代表答案 H ...
- Mybatis中jdbcType和javaType对应关系
Mybatis中javaType和jdbcType对应关系 JDBC Type Java Type CHAR String VARCHAR ...