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 ...
随机推荐
- Js 替代
替代全部:.replace(/#/g,"/") 替代第一个:.replace("#","/") var regS = new RegE ...
- Executor 和Executors
Java里面线程池的顶级接口是Executor,但是严格意义上讲Executor并不是一个线程池,而只是一个执行线程的工具.真正的线程池接口是ExecutorService. 下面这张图完整描述了线程 ...
- 基于Selenium2+Java的UI自动化(2) - 启动浏览器
一.准备工作 我们常用的浏览器主要有三个:chrome.Firefox.IE:其中chrome 和 IE 需要下载驱动程序,才能启动浏览器,注意驱动程序有32位和64位两种. 另外:如何查看本机的浏览 ...
- canvas实现“探照灯”共能
简单的样式: body{ margin: 0; padding: 0;}#canvas{ display: block; position: relative; margin: auto;} 创建绘图 ...
- 用CentOS 7打造合适的科研环境
http://seisman.info/linux-environment-for-seismology-research.html 这篇博文记录了我用CentOS 7搭建地震学科研环境的过程,供我个 ...
- asp生成静态HTML(动态读取)
这样的代码多用于我们没有实现设计生成静态的功能,但又想临时将一些动态页面生成静态的,直接获取动态内容并保存为静态的 复制代码代码如下: <!--#include file="admin ...
- SQL Server调优系列进阶篇 - 如何维护数据库索引
前言 上一篇我们研究了如何利用索引在数据库里面调优,简要的介绍了索引的原理,更重要的分析了如何选择索引以及索引的利弊项,有兴趣的可以点击查看. 本篇延续上一篇的内容,继续分析索引这块,侧重索引项的日常 ...
- ###《Effective STL》--Chapter7
点击查看Evernote原文. #@author: gr #@date: 2014-08-31 #@email: forgerui@gmail.com Chapter7 在程序中使用STL Topic ...
- 让C# Excel导入导出,支持不同版本的Office
问题:最近在项目中遇到,不同客户机安装不同Office版本,在导出Excel时,发生错误. 找不到Excel Com组件,错误信息如下. 未能加载文件或程序集“Microsoft.Office.Int ...
- Express安装与调试
Express 是基于Node.Js平台,快速.开放.极简的 web 开发框架. 1.安装 Express的安装通过cmd来进行,过程如下: 首先,先在本地建立一个项目文件夹,取名Nodejs. 然后 ...