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 ...
随机推荐
- 洛谷P1432 倒水问题
题目背景 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with th ...
- hud 2073
#include<stdio.h> #include<math.h> int main() { int i,j,k,n,m,t; double a]; a; for;i++) ...
- 细胞分裂(洛谷 P1069)
题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家.现在,他正在为一个细胞实 验做准备工作:培养细胞样本. Hanks 博士手里现在有 N 种细胞,编号从 1~N,一个 ...
- Codeforces917D. Stranger Trees
$n \leq 100$的完全图,对每个$0 \leq K \leq n-1$问生成树中与给定的一棵树有$K$条公共边的有多少个,答案$mod \ \ 1e9+7$. 对这种“在整体中求具有某些特性的 ...
- BZOJ1710: [Usaco2007 Open]Cheappal 廉价回文
len<=2000的字符串上,给出删掉和添加每种字符的花费,求把字符串变成回文串的最小花费. 首先每个字符添加和删除是一样的,因此花费在添加和删掉每个字符的花费中取小的. 如果每个字符的花费都是 ...
- Edit Distance(动态规划,难)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...
- [Poj2411]Mondriaan's Dream(状压dp)(插头dp)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18096 Accepted: 103 ...
- [Bzoj4722]由乃(线段树好题)(倍增处理模数小快速幂)
4722: 由乃 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 360 Solved: 131[Submit][Status][Discuss] D ...
- 权限对于目录和文件的具体含义 linux
权限对于具体文件的含义 文件上存储具体数据的地方,包括一般文件,数据库文件,二进制可执行文件等.因此权限对于文件的意义上这样都 r: 可读权限,表示可以读取该文件的内容 w:可写权限,表示可以编辑,新 ...
- 初学总结--------Java修饰符与修饰关键字(且叫修饰关键字)
Java中有类,有成员变量,有成员方法,有局部变量.他们分别能用什么来修饰? 目前学习到的类,有普通类和内部类. 一.修饰普通类: 1.public 每个文件中只有一个类能被public修饰,表示可 ...