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 ...
随机推荐
- POJ 2002 几何+hash
题目大意: 给定1000个点,寻找有多少组四点对能组成正方形 这里的题目跟上一道做的找平行四边形类似但想法却又不相同的方法 这里找任意2个点形成的一条边,那么可以根据这两个点,找到能和他们组成正方形剩 ...
- msp430项目编程27
msp430中项目---多机通信系统 1.I2C工作原理 2.I2C通信协议 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习
- jQuery的一些总结(持续更新中...)
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6693399.html 1. $.expr[':'] 过滤 ...
- java大文件的分割和合并
原文:http://www.open-open.com/code/view/1441679313430 import java.io.File; import java.io.FileInputStr ...
- jenkins的代理设置,方便下载插件
jenkins在下载插件的时候,总是网络不通,需要设置代理跨越长城 java.net.SocketTimeoutException: connect timed out Caused: java.ne ...
- 【APUE】进程间通信之管道
管道是UNIX系统IPC最古老形式,并且所有UNIX系统都提供此种通信机制.管道由下面两种局限性: 1)历史上,它们是半双工的(即数据只能在一个方向上流动) 2)它们只能在具有公共祖先的进程之间使用. ...
- Linux 常用检测命令
1.uptime [root@smgsim02 ~]# uptime 15:08:15 up 98 days, 4:19, 2 users, load average: 0.07, 0.29, ...
- iOS设计模式 - (1)概述
近期可自由安排的时间比較多, iOS应用方面, 没什么好点子, 就先放下, 不写了.花点时间学学设计模式. 之后将会写一系列博文, 记录设计模式学习过程. 当然, 由于我自己是搞iOS的, 所以之后设 ...
- Office EXCEL 如何保留两位小数,四舍五入
选中若干单元格,然后右击设置单元格格式,数值中保留两位小数 使用round函数四舍五入,如下图所示,我在N10单元格中输入"ROUND(M10,1)"即可,其中ROUND是函数 ...
- 微信小程序实战之 pay(支付页面)
项目目录: 逻辑层: pay.js // pages/pay/pay.js Page({ /** * 页面的初始数据 */ data: { resultType: "", resu ...