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. java中byte和blob互转

    1. btye[]转blob byte[] bs = ... Blob blob = conn.createBlob(); blob.setBytes(1, bs); ps.setBlob(2, bl ...

  2. discuzx完全自定义设计模板门户首页,栏目,专题模板方法

    第一种:门户首页模板(index.htm,保存于templatedefaultportal) <!--{subtemplate common/header}--> <style id ...

  3. 用Time Machine做更换电脑工具

    简介: Time Machine这个工具,是直接备份硬盘上的内容.所以,它是直接有备份系统的. 准备: 1.准备一个移动硬盘,存贮空间大于你需要备份系统空间 操作流程: 1. 用Disk Utilit ...

  4. Sublime搭建nodejs环境(windows)

    1.下载nodejs,并安装ok后,配置好环境变量. 2.下载sublime text3 3.在package install 包中新增node插件(或者直接去SublimeText-Nodejs插件 ...

  5. JavaScript之Cookie讲解

    什么是 Cookie “cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie.你可以使用 JavaScript 来创建和取回 cookie ...

  6. linux下解压命令大全(转载)

    .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ——————————————— .gz 解压 ...

  7. 使用WCF服务的客户端出现maxReceivedMessageSize异常

    使用WCF服务的客户端出现maxReceivedMessageSize异常解决方案 当使用WCF的客户端调取的数据过多时,会出现这个异常.一般情况下,系统默认值是65536,大约容纳100-200条左 ...

  8. SOA之(5)——REST的SOA(SOA with REST)概念

    REST的SOA(SOA with REST)概念 发展 1992年网站(Web Sites)是在Web浏览器和Web服务器直接通过HTTP传输HTML. 2000年WS-* (Web Service ...

  9. 教你如何利用xml格式的sitemap文件做好SEO

    教你如何利用xml格式的sitemap文件做好SEO 浏览: | 更新:-- : 一般的网站中都有网站地图文件,它有HTML格式与XML格式,网站地图可以帮助搜索引擎抓取.帮助用户找到自己所需要的内容 ...

  10. Java异常类和自定义异常类

    自定义异常类: public class ExtendsException extends Exception { private static final long serialVersionUID ...