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]题解的更多相关文章

  1. ICPC — International Collegiate Programming Contest Asia Regional Contest, Yokohama, 2018–12–09 题解

    目录 注意!!此题解存在大量假算法,请各位巨佬明辨! Problem A Digits Are Not Just Characters 题面 题意 思路 代码 Problem B Arithmetic ...

  2. [CCF2015.12]题解

    201512-1 数位之和 水题一个,取模除以10胡搞即可(不知道字符串为什么不行 #include <algorithm> #include <iostream> #incl ...

  3. HDU 3172 Virtual Friends(map+并查集)

    Virtual Friends Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tot ...

  4. Windows7WithSP1/TeamFoundationServer2012update4/SQLServer2012

    [Info   @09:03:33.737] ====================================================================[Info   @ ...

  5. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  6. 2018.09.02 Atcoder Regular Contest 102简要题解

    比赛传送门 T1 Triangular Relationship 分析之后发现有两种情况: 1. n为奇数,那么所有数都是k的倍数. 2. n为偶数,那么所有数都是k/2的倍数. 然后就可以愉快A题了 ...

  7. 2016ACM-ICPC Qingdao Online青岛网络赛题解

    TonyFang+Sps+我=5/12 滚了个大粗 2016年9月21日16:42:36 10题完工辣 01 题意:求形同的数中大于n的最小值 题解:预处理所有的(5194个),在这里面二分 #inc ...

  8. Codevs 1287 矩阵乘法&&Noi.cn 09:矩阵乘法(矩阵乘法练手题)

    1287 矩阵乘法  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 小明最近在为线性代数而头疼, ...

  9. 线性规划与网络流24题●09方格取数问题&13星际转移问题

    ●(做codevs1908时,发现测试数据也涵盖了1907,想要一并做了,但因为“技术”不佳,搞了一上午) ●09方格取数问题(codevs1907  方格取数3) 想了半天,也没成功建好图: 无奈下 ...

随机推荐

  1. 【BZOJ】【3530】【SDOI2014】数数

    AC自动机/数位DP orz zyf 好题啊= =同时加深了我对AC自动机(这个应该可以叫Trie图了吧……出边补全!)和数位DP的理解……不过不能自己写出来还真是弱…… /************* ...

  2. R 实例1

    //转载:http://www.r-china.net/forum.php?mod=viewthread&tid=881&extra=page%3D1//用R抓取人民日报网数据 lib ...

  3. 系统集成之用户统一登录( LDAP + wso2 Identity Server)

    本文场景: LDAP + wso2 Identity Server + asp.net声明感知 场景 ,假定读者已经了解过ws-*协议族,及 ws-trust 和 ws-federation. 随着开 ...

  4. String str=new String("a")和String str = "a"有什么区别?

    问:String str=new String("a")和String str = "a"有什么区别? 答:String str = "a" ...

  5. iOS Automation Test

    google resource for KIF: http://www.oschina.net/translate/ios-ui-testing-with-kif

  6. 关于Web与JS

    Web包含的范围比较广, JS只是代码逻辑而已. Web比如HTTP Message, SOAP Message, 浏览器流程,工具等. 不仅仅是代码.

  7. nginx js、css多个请求合并为一个请求(concat模块)

    模块介绍 mod_concat模块由淘宝开发,目前已经包含在tengine中,并且淘宝已经在使用这个nginx模块.不过塔暂时没有包含在nginx中.这个模块类似于apache中的modconcat. ...

  8. uva12534 Binary Matrix 2(最小费用最大流)

    http://blog.csdn.net/qq564690377/article/details/17082055 做的时候觉得明显是费用流,但是真的不知道怎么建图,看了上面的博客会稍微清晰一点.后面 ...

  9. LA 3211

    As you must have experienced, instead of landing immediately, an aircraft sometimes waits in a holdi ...

  10. POJ 1961 2406 (KMP,最小循环节,循环周期)

    关于KMP的最短循环节.循环周期,请戳: http://www.cnblogs.com/chenxiwenruo/p/3546457.html (KMP模板,最小循环节) POJ 2406  Powe ...