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 ...
随机推荐
- 解决Genymotion运行Android 5.0一直卡在开机界面
在一些机器,启动genymotion 的android5.0版模拟器时,会卡在启动界面,一直启动不了. 这是因为要求的开启虚拟选项没有打开,在第一次启动时,会有提示,但可能大家没有注意(我也没注意到, ...
- Java jsp页面中jstl标签详解
JSLT标签库,是日常开发经常使用的,也是众多标签中性能最好的.把常用的内容,放在这里备份一份,随用随查.尽量做到不用查,就可以随手就可以写出来.这算是Java程序员的基本功吧,一定要扎实. JSTL ...
- 希尔排序(shell)
希尔排序: 思路: 希尔排序是插入排序的一种改进的版本. 先将整个待排序记录序列分割成若干个子序列,在在序列内分别进行直接插入排序,待整个序列基本有序时,再对全体记录进行一次直接插入排序. 这里增量序 ...
- mysql针对转义字符的模糊搜索
由于urlencode之后会产生很多'%'符号,这个符号在mysql模糊搜索中代表任意字符,显示会出现问题,例如 name字段经过urlencode之后变成‘%E6%9D%8E%E5%87%A1’,如 ...
- Xcode waring: no rule to process file *** 警告提示
在编译程序的时候,Xcode给出了警告:warning: no rule to process file *** 类似的警告, 解决方法: 在[build Phases] -> [Compile ...
- ubuntu-12.04下安装postgresql
2013-10-01 20:42:57| moniter参考资料:Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装)一.安装postgresqlbamboo@bam ...
- Linux--进程组、会话、守护进程(转)
http://www.cnblogs.com/forstudy/archive/2012/04/03/2427683.html 进程组 一个或多个进程的集合 进程组ID: 正整数 两个函数 getpg ...
- Codeforces 938G(cdq分治+可撤销并查集+线性基)
题意: 有一个无向连通图,支持三个操作: 1 x y d : 新建一条x和y的无向边,长度为d 2 x y :删除x和y之间的无向边 3 x y :询问x到y的所有路径中(可以绕环)最短的 ...
- C# 获得图片的分辨率和大小
double DPI = pictureBox1.Image.HorizontalResolution;//获得分辨率 gisoracle double w = 1.0 * pictureBox1.I ...
- [Analytics] Add Tealium debugger in Chrome
It would be helpful once you can see what information have been tracking inside you web application, ...