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的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces 510 E. Fox And Dinner

    题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两 ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. Codeforces 510 A.Fox and Snake

    题目链接:http://codeforces.com/contest/510/problem/A A. Fox And Snake time limit per test2 seconds memor ...

随机推荐

  1. 第三百一十八节,Django框架,信号

    第三百一十八节,Django框架,信号 Django中提供了“信号调度”,用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. 也就是当程序有指定动作时, ...

  2. resize2fs: Bad magic number in super-block while trying to open

    I am trying to resize a logical volume on CentOS7 but am running into the following error: resize2fs ...

  3. CentOS后台运行和关闭、查看后台任务命令

    fg.bg.jobs.&.nohup.ctrl+z.ctrl+c 命令 一.& 加在一个命令的最后,可以把这个命令放到后台执行,如 watch -n 10 sh test.sh &am ...

  4. 基于PhoneGap3.4框架的iOS插件的实现

    Phonegap 提供了iOS 设备的基础特性接口来供HTML页面调用,可是这些基础接口不能满足我们的一些特殊需求,所以有时候我们须要开发插件来扩展其功能. 基于PhoneGap3.4框架的iOS插件 ...

  5. c++ __int64

    C++的64位整数[原]by 赤兔 在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-2^31,2^31),即-2147483648 ...

  6. 怎样设置easyui中datagrid行高

    $('#face_table2').datagrid({            title: '信息',            iconCls: 'icon-save',   url: 'callro ...

  7. C#实现大数相加

    在C#中,我们经常需要表示整数.但是,c#的基本数据类型中,最大的long也只能表示-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807之间的数 ...

  8. linux中,ssh实现免密自动登录到远程主机,ssh信任的实现

    需求描述: 平时使用ssh的时候,一般使用ssh都是通过用户名和密码登录到远程主机上, 然后执行一些命令,远程登录过程中,需要手动的输入密码(提示输入密码之后), 但是,在实际的应用过程中,涉及到让脚 ...

  9. android 应用能够安装在什么地方

    眼下我们仅仅能做到将应用安装在例如以下组合中:   1.关闭MTK_2SDCARD_SWAP,能够将应用安装在以下两个路径上      1)手机内存(internal storage)      2) ...

  10. 工作流JBPM_day01:6-执行流程实例

    工作流JBPM_day01:6-执行流程实例 执行流程 启动流程实例 查询任务列表 办理任务 向后执行一步 先部署流程定义在启动流程实例 Jbpm4_execution表表示正在执行的流程实例的的信息 ...