Codeforces Round #359 div2
Problem_A(CodeForces 686A):
题意:
\]
你初始有x个冰淇淋。
问最后有多少个孩纸失望的离开了。
思路:
模拟就好了, 判断当前的数目是否足够。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000000
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n;
LL x;
int main()
{
LL res, child_num;
scanf("%d %I64d", &n, &x);
res = x;
child_num = 0;
LL total_num = 0;
LL d;
char op[2];
for(int i = 0; i < n ;i ++)
{
scanf("%s %I64d", op, &d);
if(op[0] == '+')
res += d;
else if(op[0] == '-')
{
total_num ++;
if(d <= res)
{
res -= d;
child_num ++;
}
}
}
printf("%I64d %I64d\n", res, total_num - child_num);
return 0;
}
Problem_B(CodeForces 686B):
题意:
你能做如下操作:
[l, r]保证长度为偶数。
\]
你最后的目的是将其交换成一个非递减的数列。
请将交换过程中的l, r输出。
思路:
n<100, 可以很暴力的去冒泡, 因为最差的情况也不会超过100*100次。
而题目给的是2W次以内。
昂, 我比较傻逼的写了一个贪心。
每次去找最长的能够交换的区间, 然后进行操作, 一直到不能操作为止。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 110
#define MAXM 100
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n;
int a[MAXN];
int find_(int l, int r, bool is_l)
{
if(l > r) return l - 1;
for(int i = l; i + 1 <= r; i +=2)
if((a[i] <= a[i + 1] && is_l == false) || (a[i] > a[i + 1] && is_l == true)) return is_l ? i : i - 1;
return is_l ? -1 : ((r - l + 1) % 2 == 0 ? r : r - 1);
}
void move_(int l, int r)
{
for(int i = l; i < r; i += 2)
{
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
void show()
{
for(int i = 1; i <= n; i ++)
printf("%d ", a[i]);
printf("\n");
}
void deal()
{
int l = 1, r;
while(true)
{
l = find_(1, n, true);
if(l == -1)
{
l = find_(2, n, true);
if(l == -1) return ;
}
r = find_(l + 2, n, false);
if(r == -1) return;
// printf("==>%d %d\n", l, r);
move_(l, r);
// show();
// pa
printf("%d %d\n", l, r);
}
}
int main()
{
bool flag = true;
a[0] = 0;
scanf("%d", &n);
flag = n == 1;
for(int i = 1; i <= n; i ++)
{
scanf("%d", &a[i]);
if(a[i] > a[i - 1] && n && i > 1) flag = false;
}
if(!flag)
deal();
return 0;
}
Problem_C(CodeForces 686C):
题意:
给你n, m,将其转换成对应的7进制
然后从转换后的[0, n-1]中任选一个数, 再从转换后[0,m-1]中任选一个数。
必须要保证每个数字只出现一次, 即不会有重复的数字。
问你这样的组合有多少种。
思路:
因为是7进制, 而且要保证每位都不一样, 7进制只有7个数而已, 所以如果两个数的长度超过了7, 肯定不行。
\]
\]
枚举0~n, 0~m。 将其分解成对应的7进制后判断是否出现相同数字即可。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000000
#define MAXM 10
#define dd {cout<<"debug"<<endl;}
#define pa {system("pause");}
#define p(x) {printf("%d\n", x);}
#define pd(x) {printf("%.7lf\n", x);}
#define k(x) {printf("Case %d: ", ++x);}
#define s(x) {scanf("%d", &x);}
#define sd(x) {scanf("%lf", &x);}
#define mes(x, d) {memset(x, d, sizeof(x));}
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n, m;
int left_len = 0, right_len = 0;
int check(int x, int y)
{
int used[MAXM] = {0};
for(int i = x, k = 0; k < left_len; k ++, i /= 7)
used[i % 7] += 1;
for(int i = y, k = 0; k < right_len; k ++, i /= 7)
used[i % 7] += 1;
for(int i = 0; i < 7; i ++)
if(used[i] > 1) return 0;
return 1;
}
int main()
{
scanf("%d %d", &n, &m);
left_len = right_len = 1;
for(int i = 7; i < n; i *= 7)
left_len ++;
for(int i = 7; i < m; i *= 7)
right_len ++;
int ans = 0;
if((left_len + right_len) <= 7)
{
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
ans += check(i, j);
}
printf("%d\n", ans);
return 0;
}
Orz 有点头痛,剩下的等明天再补。今天元气大伤
Codeforces Round #359 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #359 (Div. 2)C - Robbers' watch
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)
题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...
随机推荐
- 使用GDB调试Android NDK native(C/C++)程序
使用GDB调试Android NDK native(C/C++)程序 先说明下,这里所谓的ndk native程序跟Android上层java应用没有什么关系,也不需要涉及jni来封装native接口 ...
- typedef的使用2——定义函数
#include <stdio.h> #include <string.h> #pragma warning(disable:4996) //闲言碎语都先不要讲了,直接上函数吧 ...
- nc命令用法举例
什么是nc nc是netcat的简写,有着网络界的瑞士军刀美誉.因为它短小精悍.功能实用,被设计为一个简单.可靠的网络工具 nc的作用 (1)实现任意TCP/UDP端口的侦听,nc可以作为server ...
- 聊聊css盒子模型
css盒子模型原理: 在网页设计中常听的属性名:内容(content).填充/内边距(padding).边框(border).外边距(margin), CSS盒子模式都具备这些属性. 这些属性我们可以 ...
- 按照行拆分textarea
网上查到方法 textarta=request("textarea") '获取数据 linestr=split(textarea,vbcrlf) '按回车将数据拆分成以行为单位的数 ...
- 通用安全字符串输入,彻底替换server.htmlencode
Function HTMLEncode(Str) If Isnull(Str) Then HTMLEncode = "" Exit Function End If Str = Re ...
- 我的MFC学习之路(一)
因为项目需求,我开始应用MFC写程序.具体接触MFC的时间大概也有两个月了.现在的水平算是刚刚踏入了MFC大门的半只脚.目前能基本使用MFC Class Wizard,可以根据实例仿照完成需求,小范围 ...
- Microsoft Word 的键盘快捷方式
Microsoft Word 的键盘快捷方式 全部显示 全部隐藏 本帮助文章中描述的键盘快捷方式适用于美式键盘布局.其他键盘布局的键可能与美式键盘上的键 不完全对应. 注释 本文不介绍如何为宏或自 ...
- MVC构架思想
一.构架的基本思想 采用MVC构架一个网站时,最好随时随地地将脑袋中切割成三份(M,V,C),这是一个最基本的切割单位,而且也是最容易切割的三个部分,但是在实务上,通常不会这么简单,有时候我们会再多切 ...
- CSS高度塌陷
问题描述:当父元素只包含浮动的元素的时候,且父元素没有设置高度,如果父元素设置了边框border,那么看起来子元素不在父元素之内. 比如这样: html: <div id="paren ...