codeforces#510 Div2
pre过了三题 后来A题被hack了 B题终测挂了 两题其实都是有一个小细节没有处理好 中间C还因为cinT了一次
唉本来打的还不错的 还是太菜了 继续加油吧
A-Benches
有n张椅子 原来第i张上有ai个人 现在来了m个人
求最大值的最大和最小的可能
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> using namespace std; int n, m;
const int maxn = ;
int a[maxn]; int main()
{
while (cin >> n >> m) {
int maxpeo = -;
for (int i = ; i < n; i++) {
cin >> a[i];
maxpeo = max(maxpeo, a[i]);
} int maxk = maxpeo + m;
int sub = ;
for (int i = ; i < n; i++) {
sub += maxpeo - a[i];
}
int mink;
if(sub >= m){
mink = maxpeo;
}
else if ((m - sub) % n == ) {
mink = (m - sub) / n + maxpeo;
}
else {
mink = (m - sub) / n + + maxpeo;
} cout<<mink<<" "<<maxk<<endl;
}
}
B-Vitamins
有n瓶果汁,每瓶有一个价格 和 可能含有的维生素【最多只有ABC三种维生素】
现在想要用最少的钱集齐ABC
本来感觉是dp 写不出 所以先去写了C 后来发现其实贪心就能过
分类讨论一下 一种是 直接选三个维生素都有的里面价格最小的
一种是 选两个维生素加缺的里面价格最小的
一种是 选单个维生素价格最小的之和
存好含三种的果汁 两种的果汁 含A的果汁【不包括三种都有】含B的含C的
第一种可能只有一种情况
第二种可能 枚举 跑一遍
第三种可能也只有一种情况
比一下最小值
需要注意有可能有的数量是0
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> #define inf 0x3f3f3f3f using namespace std; const int maxn = ;
int n;
struct node {
int c;
char vitamin[];
}juice[maxn];
node a[maxn], b[maxn], c[maxn], three[maxn], two[maxn]; bool cmp(node a, node b)
{
return a.c < b.c;
} int main()
{
while (scanf("%d", &n) != EOF) {
int cnta = , cntb = , cntc = , cntth = , cnttwo = ;
for (int i = ; i < n; i++) {
scanf("%d %s", &juice[i].c, juice[i].vitamin);
if (strlen(juice[i].vitamin) == ) {
three[cntth++] = juice[i];
}
else if (strlen(juice[i].vitamin) == ) {
two[cnttwo++] = juice[i];
for (int j = ; j < ; j++) {
if (juice[i].vitamin[j] == 'A') {
a[cnta++] = juice[i];
}
else if (juice[i].vitamin[j] == 'B') {
b[cntb++] = juice[i];
}
else {
c[cntc++] = juice[i];
}
}
}
else {
if (juice[i].vitamin[] == 'A') {
a[cnta++] = juice[i];
}
else if (juice[i].vitamin[] == 'B') {
b[cntb++] = juice[i];
}
else {
c[cntc++] = juice[i];
}
}
} if (cntth == && (cnta == || cntb == || cntc == )) {
printf("-1\n");
continue;
} sort(three, three + cntth, cmp);
sort(two, two + cnttwo, cmp);
sort(a, a + cnta, cmp);
sort(b, b + cntb, cmp);
sort(c, c + cntc, cmp); int ans;
if(cntth == ){
ans = inf;
}
else{
ans = three[].c;
}
for (int i = ; i < cnttwo; i++) {
if (strcmp(two[i].vitamin, "AB") == || strcmp(two[i].vitamin, "BA") == ) {
ans = min(ans, two[i].c + c[].c);
}
else if (strcmp(two[i].vitamin, "AC") == || strcmp(two[i].vitamin, "CA") == ) {
ans = min(ans, two[i].c + b[].c);
}
else {
ans = min(ans, two[i].c + a[].c);
}
}
if(cnta != && cntb != && cntc != ){
ans = min(ans, a[].c + b[].c + c[].c);
} printf("%d\n", ans);
}
}
C-Array Product
给一组数列 做n-1次操作
有两种操作 :第一种将ai和aj相乘结果赋给aj,ai删除
第二种 将ai位置删除【这种操作最多只能一次】
其实也是贪心
首先 所有的0都要合并 然后删去
负数 如果是奇数个的话 删去绝对值最小的那个
如果既有0又有奇数个负数 就把这个负数和0合并再删去
剩下的这些全部照常做第一种操作就好了
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> #define inf 0x3f3f3f3f using namespace std; int n;
const int maxn = 2e5 + ;
int a[maxn];
bool vis[maxn]; int main()
{
//freopen("C:\\Users\\wyb\\Desktop\\tmpcode\\codeforces\\in.txt", "r", stdin);
//freopen("C:\\Users\\wyb\\Desktop\\tmpcode\\codeforces\\out.txt", "w", stdout);
while (scanf("%d", &n) != EOF) {
memset(vis, , sizeof(vis));
int cntmin = , lastzero = -, maxminpos, maxmin = -inf, cnt = ;
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == ) {
if (lastzero == -) {
lastzero = i;
}
else {
printf("1 %d %d\n", lastzero, i);
//cout << "1 " << lastzero << " " << i << endl;
vis[lastzero] = false;
lastzero = i;
cnt++;
}
}
if (a[i] < ) {
cntmin++;
if (maxmin < a[i]) {
maxmin = a[i];
maxminpos = i;
}
}
}
if (cntmin % && lastzero != -) {
if(cnt == n - ){
continue;
}
cnt++;
printf("1 %d %d\n", maxminpos, lastzero);
//cout << "1 " << maxminpos << " " << lastzero << endl;
if(cnt == n - ){
continue;
}
cnt++;
printf("2 %d\n", lastzero);
//cout << "2 " << lastzero << endl;
vis[maxminpos] = vis[lastzero] = false;
}
else if (lastzero != -) {
if(cnt == n - ){
continue;
}
cnt++;
printf("2 %d\n", lastzero);
//cout << "2 " << lastzero << endl;
vis[lastzero] = false;
}
else if(cntmin % ){
if(cnt == n - ){
continue;
}
cnt++;
printf("2 %d\n", maxminpos);
//cout<<"2 "<<maxminpos<<endl;
vis[maxminpos] = false;
} int last = -;
for (int i = ; i <= n; i++) {
if (vis[i]) {
if (last == -) {
last = i;
}
else {
if(cnt == n - ){
break;
}
cnt++;
printf("1 %d %d\n", last, i);
//cout << "1 " << last << " " << i << endl;
last = i;
}
}
}
//cout<<endl;
}
}
codeforces#510 Div2的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces 510 E. Fox And Dinner
题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- Codeforces 510 A.Fox and Snake
题目链接:http://codeforces.com/contest/510/problem/A A. Fox And Snake time limit per test2 seconds memor ...
随机推荐
- 详解JNDI的lookup资源引用 java:/comp/env
ENC的概念: The application component environment is referred to as the ENC, the enterprise naming c ...
- SVN版本冲突,导致出现Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。
SVN版本冲突,导致出现Files 的值“ < < < < < < < .mine”无效.路径中具有非法字符. 右键编辑.... 打开并删除含有'<&l ...
- notepadd添加插件
markdown相关插件: https://www.cnblogs.com/tocy/p/npp-support-markdonw-extension.html
- Oracle Net Manager 服务命名配置以及用PL/SQL 登陆数据库
我们知道,要连接一个数据库需要知道四个参数: 1. 登陆用户名:user: 2. 登录密码:password: 3. 存放数据库的服务器地址(server_ip)和端口(server_port): 4 ...
- idea 新建项目 文件名都是红色的处理办法
原因是当前的project用了版本控制器 所以这个project下面所有的项目都加入版本控制器里了,所以项目文件和名称都是红色的 简单文字叙述解决办法 file-->settings--> ...
- cesium入门1
本教程将获得所有技能水平的开发人员和他们的第一个铯应用程序运行. 验证Cesium在您的Web浏览器中工作的最简单的方法是单击此处运行Hello World示例 (打开一个新窗口).如果你看到像下面的 ...
- JAVA程序员应该看的15本书的电子版
转载▼ 转载自:http://blog.sina.com.cn/s/blog_8297f0d00100v5ew.html 作为Java程序员来说,最痛苦的事情莫过于可以选择的范围太广,可以读的书太多, ...
- List<T>与ObservableCollectio<T> 的区别
在WPF中绑定通常会使用ObservableCollection,为什么不使用List呢? 简单是解释:List不包含值变通知功能,所以绑定了也许会出现绑定的数据与呈现数据不一致的问题. 通常绑定会使 ...
- 把握linux内核设计思想(七):内核定时器和定时运行
[版权声明:尊重原创,转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 前面章节说到了把工作推后到除如今以外的时间运行的机制是下半部机 ...
- POJ 1742 Coins(多重背包, 单调队列)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...