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】【2765】【JLOI2010】铁人双项比赛

    计算几何/半平面交 本来我是想去写POJ 1755的,然后想起了这道跟它很像的题,但应该是弱化版,所以就先写了这个…… 我们可以发现每个人的总用时,与k是呈一次函数关系的:$time_i=\frac{ ...

  2. UIResponder

    原网址:http://www.cnblogs.com/kuku/archive/2011/11/12/2246389.html 在 iOS 中,一个 UIResponder 对象表示一个可以接收触摸屏 ...

  3. Phyre LCUE with YEBIS cause issues about GS

    when LCUE enabled in phyreEngine when Yebis integrated and render there are two mainloopdraws in one ...

  4. Hadoop的RPC框架介绍

    为什么会引入RPC: RPC采用客户机/服务器模式.请求程序就是一个客户机,而服务提供程序就是一个服务器.当我们讨论HDFS的,通信可能发生在: Client-NameNode之间,其中NameNod ...

  5. Mac下使用Apache TCPMon

    Mac下使用Apache TCPMon 参考链接: TCPMon Tutorial Anyone know how to get TCPMON working on a mac? Apache TCP ...

  6. 原 JS监听回车事件

    原 JS监听回车事件 发表于2年前(2014-06-04 10:16)   阅读(6101) | 评论(0) 11人收藏此文章, 我要收藏 赞0 1月16日厦门 OSC 源创会火热报名中,奖品多多哦  ...

  7. appium获取android app的包名和主Activity

    方法一在appium的android setting中选择下载到电脑上的app包,获取Activity. 方法二在android-sdk中安装build-tools包,进入这个目录.aapt dump ...

  8. Runtime的用法

    public class RuntimeTest { public static void main(String[] args) { Runtime run =Runtime.getRuntime( ...

  9. 在linux服务器上装svn版本管理,自动部署代码到项目

    在linux服务器上装svn版本管理,自动部署代码到项目 http://bbs.aliyun.com/read/9715.html?spm=5176.7114037.1996646101.1.W3zw ...

  10. Visual Studio 项目中添加include, lib, dll库文件(*.h,*.lib,*.dll)

    应用程序使用外部库时需要进行加载,两种库的加载本质上都是一样:提供功能和功能的定义.vs2005 c++ 项目设置外部库方法如下: 1. 添加编译所需要(依赖)的 lib 文件     在“项目-&g ...