201509-1 数列分段
水,记下前一个数,看看跟当前是否一样,不一样就ans+1
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 int n, a; 23 24 int main() { 25 // freopen("in", "r", stdin); 26 while(~scanf("%d", &n)) { 27 scanf("%d", &a); 28 int cur = a, cnt = 1; 29 for(int i = 1; i < n; i++) { 30 scanf("%d", &a); 31 if(cur != a) { 32 cnt++; 33 cur = a; 34 } 35 } 36 printf("%d\n", cnt); 37 } 38 return 0; 39 }
1
201509-2 日期计算
打表,注意细节就行
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 const int com[15] = {0,31,59,90,120,151,181,212,243,273,304,334, 365}; 23 const int lep[15] = {0,31,60,91,121,152,182,213,244,274,305,335, 366}; 24 int y, c, m, d; 25 26 int main() { 27 // freopen("in", "r", stdin); 28 while(~scanf("%d %d", &y, &c)) { 29 d = 0; 30 if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) { 31 for(int i = 1; i <= 12; i++) { 32 if(lep[i] < c) { 33 m = i; 34 } 35 else break; 36 } 37 d = c - lep[m]; 38 m++; 39 if(d != 0) printf("%d\n%d\n", m, d); 40 else printf("%d\n%d\n", m, lep[m]-lep[m-1]); 41 } 42 else { 43 for(int i = 1; i <= 12; i++) { 44 if(com[i] < c) { 45 m = i; 46 } 47 else break; 48 } 49 d = c - com[m]; 50 m++; 51 if(d != 0) printf("%d\n%d\n", m, d); 52 else printf("%d\n%d\n", m, com[m]-com[m-1]); 53 } 54 } 55 return 0; 56 }
2
201509-4 高速公路
求多少个连通对。先tarjan跑出所有连通分量,然后枚举任意两个不相等的点,看看是否属于同一个连通分量里。
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 const int maxn = 10010; 23 const int maxm = 100010; 24 typedef struct Edge { 25 int u; 26 int v; 27 int next; 28 Edge() { next = -1; } 29 }Edge; 30 31 int head[maxn], ecnt; 32 Edge edge[maxm]; 33 int n, m; 34 35 int bcnt, dindex; 36 int dfn[maxn], low[maxn]; 37 int stk[maxn], top; 38 int belong[maxn]; 39 bool instk[maxn]; 40 41 void init() { 42 memset(edge, 0, sizeof(edge)); 43 memset(head, -1, sizeof(head)); 44 memset(instk, 0, sizeof(instk)); 45 memset(dfn, 0, sizeof(dfn)); 46 memset(low, 0, sizeof(low)); 47 memset(belong, 0, sizeof(belong)); 48 ecnt = top = bcnt = dindex = 0; 49 } 50 51 void adde(int uu, int vv) { 52 edge[ecnt].u = uu; 53 edge[ecnt].v = vv; 54 edge[ecnt].next = head[uu]; 55 head[uu] = ecnt++; 56 } 57 58 void tarjan(int u) { 59 int v = u; 60 dfn[u] = low[u] = ++dindex; 61 stk[++top] = u; 62 instk[u] = 1; 63 for(int i = head[u]; ~i; i=edge[i].next) { 64 v = edge[i].v; 65 if(!dfn[v]) { 66 tarjan(v); 67 low[u] = min(low[u], low[v]); 68 } 69 else if(instk[v] && dfn[v] < low[u]) { 70 low[u] = dfn[v]; 71 } 72 } 73 if(dfn[u] == low[u]) { 74 bcnt++; 75 do { 76 v = stk[top--]; 77 instk[v] = 0; 78 belong[v] = bcnt; 79 } while(v != u); 80 } 81 } 82 83 int main() { 84 // freopen("in", "r", stdin); 85 int uu, vv; 86 while(~scanf("%d %d", &n, &m)) { 87 init(); 88 for(int i = 0; i < m; i++) { 89 scanf("%d %d", &uu, &vv); 90 adde(uu, vv); 91 } 92 for(uu = 1; uu <= n; uu++) { 93 if(!dfn[uu]) { 94 tarjan(uu); 95 } 96 } 97 int ans = 0; 98 for(int i = 1; i <= n; i++) { 99 for(int j = i + 1; j <= n; j++) { 100 if(belong[i] == belong[j]) { 101 ans++; 102 } 103 } 104 } 105 printf("%d\n", ans); 106 } 107 return 0; 108 }
4
时间: 2024-09-30 19:08:58