2018-12-5 及 codeforces round 525v2
突然发现五天没记录了,这五天学习完全没有按着正常规划进行,先罗列一下吧。
- 机器学习视频第一周的全部看完了。
- 算法导论看了几页。
- 参加了一次CF。rating只加了20,看来提高实力才是最关键的。
- C++找到了侯捷老师的视频。
- 貌似记不得什么了。
记录一下昨天的CF题解吧。
题目链接:http://codeforces.com/contest/1088
A题:理论上可以用暴力搜,但是除一之外所有的答案都可以写成"x x",不再写代码解释。
B题:题意为数组中的每一个数每次都减去一个最小的数,并输出这个数。可以先排序,然后下面展示的是O(n)复杂度的算法。
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100005];
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
int sumsub = 0;
int j = 0;
while(k--){
while(j <n && a[j] <= sumsub) j++;
if(j == n) printf("0\n");
else {
printf("%d\n",a[j]-sumsub);
sumsub = a[j];
}
}
return 0;
}
C题:题目提到了两个操作,要求在n+1个操作之内讲数组变为升序。可以转化为前n个操作讲n个数对n+1的余数变为递增,然后最后一步对n+1取模。
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int a[10000];
vector<pair<int,int>> ans;
int main(){
int n ;
scanf("%d",&n);
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);
}
int cnt = 0;
int sum = 0;
for(int i = n; i >= 1; i--){
if((sum+a[i])%(n+1) == i) continue;
else {
cnt++;
int d = (sum+a[i])%(n+1);
if(i > d) {ans.push_back(make_pair(i,i-d));sum+=i-d;}
else {ans.push_back(make_pair(i,n+1+i-d));sum+=n+1+i-d;}
}
}
cnt++;
printf("%d\n",cnt);
for(int i = 0; i < cnt-1;i++){
printf("1 %d %d\n",ans[i].first,ans[i].second);
}
printf("2 %d %d",n,n+1);
return 0;
}
D题思路是对的,但是因为一些原因没有去做,不然可能这次就上蓝了。
#include<iostream>
using namespace std;
int query(int a,int b){
cout << "? "<<a<<" "<<b<<endl;
int res;
cin >> res;
return res;
}
int a = 0,b = 0;
int main(){
bool comp = (query(0,0) == 1);
for(int i = 29; i >= 0; i--){
int p = query(a,b|1<<i);
int q = query(a|1<<i,b);
if(p == 1 && q == -1){
a = a|1<<i;
b = b|1<<i;
}else if( p == -1 && q == 1){
continue;
}else{
if(comp) a = a|1<<i;
else b = b|1<<i;
comp = (p==1);
}
}
cout << "! "<<a<<" "<<b<<endl;
return 0;
}
以后每天都记录一下吧
2018-12-5 及 codeforces round 525v2的更多相关文章
- 2018.9.20 Educational Codeforces Round 51
蒟蒻就切了四道水题,然后EF看着可写然而并不会,中间还WA了一次,我太菜了.jpg =.= A.Vasya And Password 一开始看着有点虚没敢立刻写,后来写完第二题发现可以暴力讨论,因为保 ...
- Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)
Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter ...
- Codeforces Round #525 (Div. 2)
Codeforces Round #525 (Div. 2) 哎,忍不住想吐槽一下,又要准备训练,又要做些无聊的事,弄得我都想退出了. 好好的训练不好么???? 只能做出两道水题,其实C题,感觉做出来 ...
- Codeforces Round #523 (Div. 2)
Codeforces Round #523 (Div. 2) 题目一览表 来源 考察知识点 完成时间 A Coins cf 贪心(签到题) 2018.11.23 B Views Matter cf 思 ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- Codeforces Round #223 (Div. 2) A
A. Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
随机推荐
- Java知识系统回顾整理01基础01第一个程序01JDK 安装
一.首先第一步看JDK配置成功后的效果 点WIN键->运行(或者使用win+r) 输入cmd命令 输入java -version 注: -version是小写,不能使用大写,java后面有一个空 ...
- 001 发大招了 神奇的效率工具--Java代码转python代码
今天发现一个好玩的工具: 可以直接将java转成python 1. 安装工具(windows 环境下面) 先下载antlr: 下载链接如下: http://www.antlr3.org/downloa ...
- c++中CString:: Find , ReverseFind, Left, Right
CString 是在MFC中的头文件 非MFC加上afx.h头文件 直接上代码: // ConsoleApplication1.cpp : Defines the entry point for th ...
- osu合集(期望dp)
T1 EASY 我们设\(f_i\)表示到\(i\)的连续个数平方的期望. \(g_i\)表示到到\(i\)的连续个数的期望 在维护\(f_i\)的同时维护一下\(g_i\)就行了. 转移方程: \( ...
- Java中类型判断的几种方式
1. 前言 在Java这种强类型语言中类型转换.类型判断是经常遇到的.今天就细数一下Java中类型判断的方法方式. 2. instanceof instanceof是Java的一个运算符,用来判断一个 ...
- IDEA推送docker镜像到私服/利用dockerfile-maven-plugin插件在springboot中上传镜像到远程的docker服务器、远程仓库
利用dockerfile-maven-plugin插件在springboot中上传镜像到远程仓库 这篇文章讲解在开发工具中把打包好的jar编译成docker镜像,上传到远程的docker服务 ...
- vue的二级联动,数据是从php获取到的
1.首先,一级要有change改变事件的关键字,v-on:change="selectarr($event)" 这是created(){}函数里面的自动调用一级分类的数据 html ...
- java -inally转
1.不管有木有出现异常,finally块中代码都会执行: 2.当try和catch中有return时,finally仍然会执行:3.finally是在return后面的表达式运算后执行的(此时并没有返 ...
- Azure Cosmos DB (三) EF Core 操作CURD
一,引言 接着上一篇使用 EF Core 操作 Azure CosmosDB 生成种子数据,今天我们完成通过 EF Core 实现CRUD一系列功能.EF Core 3.0 提供了CosmosDB 数 ...
- C 和 C++ 打起来了!曾今最亲密的伙伴到现今的不爽?
70年代初,贝尔实验室创建了C语言,它是开发UNIX的副产品.很快C就成为了最受欢迎的编程语言之一.但是对于Bjarne Stroustrup来说,C的表达能力还不够.于是,他在1983年的博士论文中 ...