[CCF2015.09]题解
201509-1 数列分段
水,记下前一个数,看看跟当前是否一样,不一样就ans+1
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; int n, a; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n)) {
scanf("%d", &a);
int cur = a, cnt = ;
for(int i = ; i < n; i++) {
scanf("%d", &a);
if(cur != a) {
cnt++;
cur = a;
}
}
printf("%d\n", cnt);
}
return ;
}
1
201509-2 日期计算
打表,注意细节就行
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int com[] = {,,,,,,,,,,,, };
const int lep[] = {,,,,,,,,,,,, };
int y, c, m, d; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d %d", &y, &c)) {
d = ;
if((y % == && y % != ) || (y % == )) {
for(int i = ; i <= ; i++) {
if(lep[i] < c) {
m = i;
}
else break;
}
d = c - lep[m];
m++;
if(d != ) printf("%d\n%d\n", m, d);
else printf("%d\n%d\n", m, lep[m]-lep[m-]);
}
else {
for(int i = ; i <= ; i++) {
if(com[i] < c) {
m = i;
}
else break;
}
d = c - com[m];
m++;
if(d != ) printf("%d\n%d\n", m, d);
else printf("%d\n%d\n", m, com[m]-com[m-]);
}
}
return ;
}
2
201509-3 模版生成系统
字符串大模拟,无耻地大量使用了STL,甚至出现了vector<pair<vector<int>,vector<int> > >这样的结构。思路就是首先定位此行输入的字符串的需要替换的变量起止位置,再记录当前字符串。接下来读取模式串的键值,放到set中。接下来替换。要注意使用string中的replace时候会让字符串长度发生变化,这时候只要从末尾开始匹配,最后再输出就行了。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std;
typedef vector<int>::iterator it;
typedef vector<vector<int> >::iterator iit;
typedef pair<vector<int>,vector<int> > pvv;
const int maxn = ; int n, m;
vector<int> start, end;
vector<pvv> sig;
vector<string> str;
map<string, string> var;
char tmp[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d %d", &m, &n)) {
sig.clear();
var.clear();
getchar();
for(int i = ; i < m; i++) {
start.clear();
end.clear();
gets(tmp);
int len = strlen(tmp);
for(int j = ; j < len; j++) {
if(tmp[j] == ' ' && tmp[j-] == '{' && tmp[j-] == '{') start.push_back(j+);
if(tmp[j] == ' ' && tmp[j+] == '}' && tmp[j+] == '}') end.push_back(j-);
}
sig.push_back(pvv(start, end));
str.push_back(string(tmp));
}
for(int i = ; i < n; i++) {
gets(tmp);
string raw(tmp);
int j;
for(j = ; j < raw.length(); j++) {
if(raw[j] == ' ') break;
}
var[raw.substr(, j)] = raw.substr(j+, raw.length()-j-);
}
for(int i = ; i < sig.size(); i++) {
if(sig[i].first.empty()) {
printf("%s\n", str[i].c_str());
continue;
}
for(int j = sig[i].first.size() - ; j >= ; j--) {
str[i].replace(
sig[i].first[j]-, sig[i].second[j]-sig[i].first[j]+,
var[str[i].substr(sig[i].first[j], sig[i].second[j]-sig[i].first[j]+)]);
// cout << sig[i].first[j] << " " << sig[i].second[j] << endl;
// cout << str[i].substr(sig[i].first[j], sig[i].second[j]-sig[i].first[j] + 1) << endl;
}
printf("%s\n", str[i].c_str());
}
}
return ;
}
3
201509-4 高速公路
求多少个连通对。先tarjan跑出所有连通分量,然后枚举任意两个不相等的点,看看是否属于同一个连通分量里。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
const int maxm = ;
typedef struct Edge {
int u;
int v;
int next;
Edge() { next = -; }
}Edge; int head[maxn], ecnt;
Edge edge[maxm];
int n, m; int bcnt, dindex;
int dfn[maxn], low[maxn];
int stk[maxn], top;
int belong[maxn];
bool instk[maxn]; void init() {
memset(edge, , sizeof(edge));
memset(head, -, sizeof(head));
memset(instk, , sizeof(instk));
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(belong, , sizeof(belong));
ecnt = top = bcnt = dindex = ;
} void adde(int uu, int vv) {
edge[ecnt].u = uu;
edge[ecnt].v = vv;
edge[ecnt].next = head[uu];
head[uu] = ecnt++;
} void tarjan(int u) {
int v = u;
dfn[u] = low[u] = ++dindex;
stk[++top] = u;
instk[u] = ;
for(int i = head[u]; ~i; i=edge[i].next) {
v = edge[i].v;
if(!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if(instk[v] && dfn[v] < low[u]) {
low[u] = dfn[v];
}
}
if(dfn[u] == low[u]) {
bcnt++;
do {
v = stk[top--];
instk[v] = ;
belong[v] = bcnt;
} while(v != u);
}
} int main() {
// freopen("in", "r", stdin);
int uu, vv;
while(~scanf("%d %d", &n, &m)) {
init();
for(int i = ; i < m; i++) {
scanf("%d %d", &uu, &vv);
adde(uu, vv);
}
for(uu = ; uu <= n; uu++) {
if(!dfn[uu]) {
tarjan(uu);
}
}
int ans = ;
for(int i = ; i <= n; i++) {
for(int j = i + ; j <= n; j++) {
if(belong[i] == belong[j]) {
ans++;
}
}
}
printf("%d\n", ans);
}
return ;
}
4
[CCF2015.09]题解的更多相关文章
- ICPC — International Collegiate Programming Contest Asia Regional Contest, Yokohama, 2018–12–09 题解
目录 注意!!此题解存在大量假算法,请各位巨佬明辨! Problem A Digits Are Not Just Characters 题面 题意 思路 代码 Problem B Arithmetic ...
- [CCF2015.12]题解
201512-1 数位之和 水题一个,取模除以10胡搞即可(不知道字符串为什么不行 #include <algorithm> #include <iostream> #incl ...
- HDU 3172 Virtual Friends(map+并查集)
Virtual Friends Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tot ...
- Windows7WithSP1/TeamFoundationServer2012update4/SQLServer2012
[Info @09:03:33.737] ====================================================================[Info @ ...
- 2018.09.08 AtCoder Beginner Contest 109简要题解
比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...
- 2018.09.02 Atcoder Regular Contest 102简要题解
比赛传送门 T1 Triangular Relationship 分析之后发现有两种情况: 1. n为奇数,那么所有数都是k的倍数. 2. n为偶数,那么所有数都是k/2的倍数. 然后就可以愉快A题了 ...
- 2016ACM-ICPC Qingdao Online青岛网络赛题解
TonyFang+Sps+我=5/12 滚了个大粗 2016年9月21日16:42:36 10题完工辣 01 题意:求形同的数中大于n的最小值 题解:预处理所有的(5194个),在这里面二分 #inc ...
- Codevs 1287 矩阵乘法&&Noi.cn 09:矩阵乘法(矩阵乘法练手题)
1287 矩阵乘法 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 小明最近在为线性代数而头疼, ...
- 线性规划与网络流24题●09方格取数问题&13星际转移问题
●(做codevs1908时,发现测试数据也涵盖了1907,想要一并做了,但因为“技术”不佳,搞了一上午) ●09方格取数问题(codevs1907 方格取数3) 想了半天,也没成功建好图: 无奈下 ...
随机推荐
- 【BZOJ】【1855】【SCOI2010】/【HDOJ】【3401】股票交易
DP/单调队列优化 题解:http://www.cnblogs.com/jianglangcaijin/p/3799736.html 令f[i][j]表示第 i 天结束后,手里剩下 j 股的最大利润, ...
- 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉
DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $ 当然这里的$i$和$k$都是偶数啦~ ...
- 【BZOJ】【3850】ZCC Loves Codefires
贪心 就跟NOIP2012国王游戏差不多,考虑交换相邻两题的位置,对其他题是毫无影响的,然后看两题顺序先后哪个更优.sort即可. WA了一次的原因:虽然ans开的是long long,但是在这一句: ...
- logback日志项目使用方法 - 150205交易模块添加日志信息logback,orderNo订单号为log主键便于跟踪,数字常量化,解决取消支付BUG,弱网络环境原因
1.项目里面的日志,便于跟踪数据的变更和异常错误信息产生.生产环境的日志级别是INFO,测试环境日志级别DEBUG,如果生产环境的日志级别是DEBUG,虽然方便查询问题,可以看到SQL语句等信息,但是 ...
- iOS项目的完整重命名方法图文教程
原文链接:http://www.cocoachina.com/ios/20150104/10824.html iOS项目的完整重命名方法图文教程 前言:在iOS开发中,有时候想改一下项目的名字,都会遇 ...
- HDU 1558 Segment set (并查集+线段非规范相交)
题目链接 题意 : 如果两个线段相交就属于同一集合,查询某条线段所属集合有多少线段,输出. 思路 : 先判断与其他线段是否相交,然后合并. #include <cstdio> #inclu ...
- 2014多校第二场1011 || HDU 4882 ZCC Loves Codefires (贪心)
题目链接 题意 : 给出n个问题,每个问题有两个参数,一个ei(所要耗费的时间),一个ki(能得到的score).每道问题需要耗费:(当前耗费的时间)*ki,问怎样组合问题的处理顺序可以使得耗费达到最 ...
- HDU5569/BestCoder Round #63 (div.2) C.matrix DP
matrix Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at fir ...
- HTML CSS——margin与padding的初学
下文引自HTML CSS——margin和padding的学习,作者fengyv,不过加入了一些个人的看法. 你在学习margin和padding的时候是不是懵了,——什么他娘的内边距,什么他娘的外边 ...
- 关于null == 0?返回false的问题
1.首先我们先看各种情况的结果: null > 0? //=>false null < 0? //=>false null >= 0? //=>true null ...