CF640 div4

草 迟到半个月的补题

真正的懒狗

再懒就无了

  • D. Alice, Bob and Candies

    题意:n个数字,奇数时间从左侧删数字,偶数时间从右侧删数字,每次删的数字之和必须大于上次的。问最多删多少次和左边删除数字和与右边删除数字和。

    题解:很简单的模拟题,初始情况特判即可,不知道当时为什么没做出来

#include<iostream>

using namespace std;
int can[1005];
int main() {
int t;
cin >> t;
while (t--) {
int n;
int a=0, b=0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> can[i];
}
int moves = 0;
int l = 1, r = n,sum=0;
while (l<=r) {
++moves;
if (moves % 2 == 1) {
if (moves == 1) {
sum = can[l++];
a+=sum;
}
else {
int tmp = 0;
while (tmp < sum + 1&&l<=r) {
tmp += can[l++];
}
sum = tmp;
a += sum;
if (l > r) {
break;
}
}
}
else {
int tmp = 0;
while (tmp < sum + 1 && l <= r) {
tmp += can[r--];
}
sum = tmp;
b += sum;
if (l > r) {
break;
}
}
}
cout << moves << " " << a << " " << b << endl; }
}
  • E.Special Elements

    题意:问一组数中有多少个数可以表示成数组的区间和。

    题解:前缀和

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[8010], sum[8010], num[8010];
int main() {
int t;
cin >> t;
while (t--) { int cnt = 0;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
num[a[i]]++;
sum[i] = sum[i - 1] + a[i];
} for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int tmp = sum[j] - sum[i-1];
if (tmp <= n && num[tmp] > 0) {
cnt += num[tmp];
num[tmp] = 0;
}
}
}
memset(num, 0, sizeof(num));
cout << cnt << endl;
}
}
  • F. Binary String Reconstruction

    题意:01串 \(n_0\)代表00个数,\(n_1\)代表\(10或01\)个数,\(n_2\)代表\(11\)个数。t次询问求合法串。

    题解:又是模拟

#include<iostream>
#include<algorithm>
#include<string>
using namespace std; int main() {
int t;
cin >> t;
while (t--) {
int a, b, c;
string s1, s2, s3;
cin >> a >> b >> c;
if(a > 0) {
int tmp = a + 1;
while (tmp--) {
s1 += "0";
}
} if (a == 0&&b>0) {
s2 += "0";
}
if (c > 0) {
b--;
}
if (b > 0) {
s2 += "1";
b--;
int cnt = 0;
while (b--) {
if (cnt % 2 == 0)
s2 += "0";
else
s2 += "1";
cnt++;
}
}
if (c > 0) {
int tmp = c + 1;
while (tmp--) {
s3 += "1";
}
}
string res = s3 + s1 + s2;
cout << res << endl;
}
}
  • G. Special Permutation

    题意题解懒得写了,深搜
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
int ac[6] = { -4,-3,-2,2,3,4 };
int flag = 0;
int vis[1005];
stack<int> s;
int n;
void dfs(int x) {
if (flag == 1) return;
if (s.size() == n) {
while (!s.empty()) {
cout << s.top() << " ";
s.pop();
}
cout << endl;
flag = 1;
return;
} for (int i = 0; i <= 5; ++i) {
int tmp = x + ac[i];
if (tmp <= 0 || tmp > n||vis[tmp]) {
continue;
}
vis[tmp] = 1;
s.push(tmp);
dfs(tmp);
if (flag == 1) return;
vis[tmp] = 0;
s.pop();
} }
int main() {
int t;
cin >> t;
while(t--) {
cin >> n;
for (int i = n; i >0; --i) {
vis[i] = 1;
s.push(i);
dfs(i);
if (flag) {
break;
}
vis[i] = 0;
s.pop();
}
if (flag == 0) {
cout << -1 << endl;
}
flag = 0;
while (!s.empty()) {
s.pop();
}
memset(vis, 0, sizeof(vis));
}
}

现在回头一看都是rz题,为啥当时不敢写呢

CF #640 (div4)的更多相关文章

  1. Codeforces #640 div4 F~G (构造二连弹)

    题意:求一个只由\(01\)组成的字符串,使得它所有长度为\(2\)的子串满足:每对子串的数字和为\(0,1,2\)的个数为\(a,b,c\). 题解:我们先考虑子串数字和为\(1\)的情况,构造出一 ...

  2. [cf]Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

  3. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  6. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  7. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  8. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  9. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

随机推荐

  1. 看完这篇还不懂Redis的RDB持久化,你们来打我!

    一.为什么需要持久化 redis里有10gb数据,突然停电或者意外宕机了,再启动的时候10gb都没了?!所以需要持久化,宕机后再通过持久化文件将数据恢复. 二.优缺点 1.rdb文件 rdb文件都是二 ...

  2. 03.Django-ORM

    ORM 1. 数据库配置 配置使用sqlite3,mysql,oracle,postgresql等数据库 sqlite3数据库配置 DATABASES = { 'default': { # 默认使用的 ...

  3. 不可不知的辅助测试的Fiddler小技巧

    在以前的博文中,时常有分享Fiddler的一些使用技巧,今天再贴下. Fiddler抓包工具使用详解 利用Fiddler拦截接口请求并篡改数据 Fiddler使用过程中容易忽略的小技巧 Mock测试, ...

  4. 七个生产案例告诉你BATJ为何选择ElasticSearch!应用场景和优势!

    本文来源于公众号[胖滚猪学编程],转载请注明出处. 从今天开始,想和你一起死磕ElasticSearch,学习分布式搜索引擎,跟着胖滚猪就对了! 既然是ES的第一课,那么最重要的是让你爱上它!不想说那 ...

  5. 上位机C#通过OPCUA和西门子PLC通信

    写在前面: 很多人在学习OPCUA的时候,有个非常苦恼的问题,就是没有OPCUA服务器的环境,这时候,有些人可能会想到通过类似于KepServer这样的软件来实现.那么,有没有一种方式,实现快速搭建O ...

  6. Rocket - util - Replacement

    https://mp.weixin.qq.com/s/zCP7wPuxgQ-r94Tr6BV5iw   简单介绍Replacement的实现.   ​​   1. 基本介绍   用于实现Cache替换 ...

  7. html css javascript实现弹弹球

    效果如图: 原创代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  8. 本地计算机上的MySQL80服务启动后停止,某些服务在未由其他服务或者程序使用时将自动停止

    是由于mysql server XX 路径下的my.ini文件发生错误. 高版本的mysql server的my.ini文件不在mysql server XX路径下,在programdata文件夹(查 ...

  9. java方法句柄-----1.方法句柄类型、调用

    目录 方法句柄 1.方法句柄的类型 1.1MethodType类的对象实例的创建 1.1.1 通过指定参数和返回值的类型来创建MethodType.[显式地指定返回值和参数的类型] 1.1.2 通过静 ...

  10. MySQL 高级—— 锁机制

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.锁的概述 1.锁的定义 锁是计算机协调多个进程或线程并发访问某一资源的机制. 在数据库中,除传统的计 ...