codeforces 125 A-E 补题
进制转换 水题
#include<bits/stdc++.h>
using namespace std; int main()
{
int n;
scanf("%d",&n);
int a=n/36;
n-=a*36;
int b=(n)/3;
if((n%3)>=2)b++;
while(b>=12)b-=12,a+=1;
printf("%d %d\n",a,b);
return 0;
}
用栈实现的括号匹配相信大家都会
当然所有栈都可以用更直接粗暴的方法实现。
#include <iostream> using namespace std; int main()
{
string s; int x=0,y=0;
cin >> s;
for(int i=0; s[i]; i++)if(s[i]=='>')
{
if(s[i-2]=='/')y-=2;
for(int i=0; i<y; i++)cout<<" ";
for(int j=x; j<=i; j++)cout<<s[j]; cout<<endl;
if(s[i-2]!='/')y+=2;x=i+1;
}
}
很简单的贪心构造
#include<bits/stdc++.h>
using namespace std; const int N=500;
vector<int> gues[N];
int main()
{
gues[1].resize(2);gues[2].resize(2);gues[3].resize(2);
gues[1][0]=1;gues[1][1]=2;
gues[2][0]=1;gues[2][1]=3;
gues[3][0]=2;gues[3][1]=3;
int k;
scanf("%d",&k);
k-=3;
int t=3;
int i;
for( i=4;;i++)
{
if((i-1)>k)break;
for(int j=1;j<=i-1;j++)
{
gues[j].push_back((t+j));
gues[i].push_back((t+j));
}
t+=(i-1);
k-=(i-1);
}
printf("%d\n",i-1);
for(int j=1;j<i;j++)
{ for(int k=0;k<gues[j].size();k++)
printf("%d ",gues[j][k]);
printf("\n");
}
return 0;
}
给定一个序列 试问能否将它拆分成两个等差数列 满足元素之间的相对位置不改变
暴力分配每个元素属于第一个还是第二个序列即可
剪枝:每个元素对于每个公差的序列只用搜索一次(证明方法自己思考)
#include<cstdio>
#include<set>
using namespace std; int n, al, bl, ff, i;
int s[30000], a[30000], b[30000];
set<int> visa[30000], visb[30000]; void dfs(){
if(al == n) return;
if(al + bl == n) {ff = 1; return;}
if(al < 2 || s[al+bl]-a[al-1] == a[al-1]-a[al-2] && (visb[al+bl].find(a[al-1]-a[al-2])==visb[al+bl].end())){
a[al] = s[al+bl];
if(al>1) visa[al+bl].insert(a[al]-a[al-1]);
al++;
dfs();
if(ff) return;
al--;
}
if(bl < 2 || s[al+bl]-b[bl-1] == b[bl-1]-b[bl-2] && (visa[al+bl].find(b[bl-1]-b[bl-2])==visa[al+bl].end())){
b[bl] = s[al+bl];
if(bl>1) visb[al+bl].insert(b[bl]-b[bl-1]);
bl++;
dfs();
if(ff) return;
bl--;
}
} int main(){
scanf("%d", &n);
for(i = 0; i < n; i++)
scanf("%d", &s[i]);
ff = al = bl = 0;
dfs();
if(ff){
for(i = 0; i < al; i++)
printf("%d ", a[i]);
printf("\n");
for(i = 0; i < bl; i++)
printf("%d ", b[i]);
printf("\n");
}
else
printf("No solution\n");
return 0;
}
codeforces 125 A-E 补题的更多相关文章
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- codeforces round 422 div2 补题 CF 822 A-F
A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...
- codeforces round 421 div2 补题 CF 820 A-E
A Mister B and Book Reading O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...
- Codeforces round 419 div2 补题 CF 816 A-E
A Karen and Morning 水题 注意进位即可 #include<bits/stdc++.h> using namespace std; typedef long long i ...
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- codeforces 447 A-E div2 补题
A DZY Loves Hash 水题 #include<iostream> #include<cstdio> #include<cstdlib> #include ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...
- codeforces round 417 div2 补题 CF 812 A-E
A Sagheer and Crossroads 水题略过(然而被Hack了 以后要更加谨慎) #include<bits/stdc++.h> using namespace std; i ...
- Codeforces Beta Round #1 补题题解
A Theatre Square(数学) 算出每行能装多少乘以每列能装多少就行 公式 ans=ceil(n/a)+ceil(m/a) 代码 #include <bits/stdc++.h> ...
- codeforces round 416 div2 补题 CF 811 A B C D E
A. Vladik and Courtesy 水题略过 #include<cstdio> #include<cstdlib> #include<cmath> usi ...
随机推荐
- 潘多拉的盒子(bzoj 1194)
Description Input 第一行是一个正整数S,表示宝盒上咒语机的个数,(1≤S≤50).文件以下分为S块,每一块描述一个咒语机,按照咒语机0,咒语机1„„咒语机S-1的顺序描述.每一块的格 ...
- 单源最短路径 Bellman_ford 和 dijkstra
首先两个算法都是常用于 求单源最短路径 关键部分就在于松弛操作 实际上就是dp的感觉 if (dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist ...
- 删除字符串中的"\U0000fffc"数据 textView添加图片 以及添加后属性失效的解决
背景:在实现textView的富文本时,如果添加一张图片后,如果直接发送textView的内容时,图片会被字符串“\U0000fffc”替换. 问题:如何删除“\U0000fffc”字符串:如何替换t ...
- [洛谷U22158]策划体验(树上斜率优化)(二分最优决策)
题目背景 OL不在,Clao又在肝少*前线,他虽然觉得这个游戏的地图很烦,但是他认为地图的难度还是太低了,习习中作为策划还不够FM,于是他自己YY了一种新的地图和新的机制: 题目描述 整个地图呈树形结 ...
- navicat 无法连接到腾讯云Mysql
远程连接进入服务器 远程连接进入服务器之后,输入命令mysql -u root -p 之后输入mysql密码,进入mysql 命令环境 设置开启远程登录 GRANT ALL PRIVILEGES ON ...
- 洛谷 P3807 【模板】卢卡斯定理
P3807 [模板]卢卡斯定理 题目背景 这是一道模板题. 题目描述 给定n,m,p(1\le n,m,p\le 10^51≤n,m,p≤105) 求 C_{n+m}^{m}\ mod\ pCn+mm ...
- IntelliJ IDEA14.0.3+Maven+SpringMVC+Spring+Hibernate光速构建Java权限管理系统(三)
注册登录 --利用简单的编写注册登录系统来打通从前端到后台的数据传输路径. 一.建立数据库.基本表 基本环境:mysql5,7.Navicat for MySQL11.0.9企业版. 我们在本地MyS ...
- 从日志文件解决ArcGIS Server性能低下问题的步骤(1)
日志级别和结构 http://www.cnblogs.com/fortoday/archive/2011/03/30/2000348.html ArcGIS Server日志文件分为几个记录级别: 无 ...
- 条款一:尽量使用const、inline而不是#define
#define ASPECT_RATIO 1.653 编译器会永远也看不到ASPECT_RATIO这个符号名,因为在源码进入编译器之前,它会被预处理程序去掉,于是ASPECT_RATIO不会加入到符号 ...
- 【algorithm】尾递归
尾递归和一般的递归不同在对内存的占用,普通递归创建stack累积而后计算收缩,尾递归只会占用恒量的内存(和迭代一样).SICP中描述了一个内存占用曲线,用以上答案中的Python代码为例(普通递归): ...