自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

菜鸟

too difficult

  • 博客(70)
  • 收藏
  • 关注

原创 FZU 2147 A-B Game

关键是找出规律,其次再说贪心吧= =#include #include using namespace std;int main(){ int t, cas = 0; scanf("%d", &t); while (t--) { __int64 a, b; scanf("%I64d%I64d", &a, &b);

2016-03-30 22:59:56 456

原创 HDU 3790 最短路径问题

用的spfa的思想写的,我感觉用一个标记数组flag[]来标志是否在队列中,好像不是很有用啊,只要做了松弛操作,我感觉都应该入队才是吧= =。这道题目就是更新路径的时候顺便更新一下花费。#include #include #include #include #include using namespace std;const int INF = 0x3f3f3f;const int

2016-03-26 22:49:56 404

原创 HDU2544 最短路

感觉bellman 和 djikstra处理的时候都要注意是否双向= =#include #include #include using namespace std;const int INF = 0x3f3f3f;const int MAX = 1e4 + 5;struct EDGE{ int from, to, cost; EDGE(int a = 0, i

2016-03-26 19:26:11 328

原创 HDU 1875 畅通工程再续

居然是1A。和前面写过的一道修电脑的并查集的题目很像。#include #include #include #include #include using namespace std;const int MAX = 205;int fa[MAX], r[MAX];struct EDGE{ int from, to; double cost; EDG

2016-03-25 01:05:11 403

原创 HDU 1863 畅通工程

刚开始,写错一个变量名,没有被声明的变量,结果编译器没有查出错,导致我一直结果不正确,还有就是在最后一定要把vector数组清空掉。#include #include #include #include #include #include using namespace std;const int MAX = 105;const int INF = 0x3f3f3f;int

2016-03-25 00:26:27 335

原创 HDU 1233 还是畅通工程

赤裸裸的最小生成树啊。#include #include #include #include using namespace std;const int MAX = 105;int fa[MAX], r[MAX];struct EDGE{ int from, to, cost;}edge[MAX * MAX];bool comp(EDGE a, EDGE b)

2016-03-24 23:17:34 405

原创 51nod 1212 无向图最小生成树

prim算法,为什么我另一道题就错了呢。#include #include #include #include #include #include using namespace std;const int INF = 0x3f3f3f;const int MAX = 1e3 + 5;int flag[MAX], min_cost[MAX];struct EDGE{

2016-03-24 17:58:36 675

原创 HDU 1102 Constructing Roads

用的kruskal算法,主要就是把已经连接的路标记连接上,然后再求最小生成树就行了。#include #include using namespace std;const int MAX = 1e4 + 5;struct EDGE{ int from, to , cost;}edge[MAX];int n, q;int fa[105], r[105];int co

2016-03-24 10:04:39 375

原创 HDU 1213 How Many Tables

统计有多少个集合,只要fa[i] == i;就可以算作是一个单独的集合。#include #include const int MAX = 1e3 + 5;int fa[MAX], r[MAX];void init(int n){ for (int i = 1; i <= n; ++i) { fa[i] = i; r[i] = 1;

2016-03-23 14:55:28 371

原创 POJ 1611 The Suspects

辅助数组cnt,统计节点数目。#include #include using namespace std;const int MAX = 1e3 + 5;int x[MAX], y[MAX], fa[MAX], flag[MAX], r[MAX];int n, d;void init(int n){ for (int i = 1; i <= n; ++i) {

2016-03-23 14:37:20 314

原创 POJ 2236 Wireless Network

#include #include using namespace std;const int MAX = 1e3 + 5;int x[MAX], y[MAX], fa[MAX], flag[MAX], r[MAX];int n, d;void init(int n){ for (int i = 1; i <= n; ++i) { fa[i] =

2016-03-23 14:34:38 313

原创 POJ 2481 Cows

树状数组,我代码写得很清晰啊,(●ˇ∀ˇ●)#include #include #include #include using namespace std;const int MAX = 1e5 + 5;struct NODE{ int s, e, id; bool operator==(NODE& tmp) { return this

2016-03-21 19:59:35 316

原创 HDU 1166 敌兵布阵

裸的树状数组。#include #include using namespace std;const int MAX = 5e4 + 5;int arr[MAX];int n;int lowbit(int x){ return x & (-x);}int update(int k, int num){ while (k <= n) {

2016-03-21 17:23:39 305

原创 poj 2299 Ultra-QuickSort

求逆序数对#include #include #include using namespace std;const int MAX = 5e5 + 5;int arr[MAX], tmp[MAX];__int64 res;void merge_sort(int* arr, int* tmp, int l, int r){ if (l == r) re

2016-03-21 17:20:47 272

原创 HDU 2087 剪花布条

#include #include #include using namespace std;const int MAX = 1e3 + 5;char arr1[MAX], arr2[MAX];int nex[MAX];void get_next(char* p, int* nex){ int k = -1, j = 0; nex[j] = k; int

2016-03-21 10:50:06 392

原创 HDU 3746 Cyclic Nacklace

对next[]数组的理解。用cin结果WA了很多次,改成scanf就对了。#include #include #include using namespace std;const int MAX = 1e5 + 5;char arr1[MAX], arr2[MAX];int nex[MAX];void get_next(char* p, int* nex){ int

2016-03-21 10:47:55 326

原创 LightOJ 1258 - Making Huge Palindromes

字符串问题。#include #include #include #include using namespace std;const int MAX = 1e6 + 5;int next[MAX];void get_next(string& str, int* next){ int lenth = str.size(); int k = -1, j = 0; ne

2016-03-17 00:13:02 544

原创 LightOJ 1255 - Substring Frequency

字符串匹配#include #include #include const int MAX = 1e6 + 5;int next[MAX];char str[MAX], p[MAX];int res;void getNEXT(char* p, int* next){ next[0] = -1; int k = -1, j = 0; int lenth = strlen

2016-03-16 21:23:34 457

原创 CodeForces 624B - Making a String

贪心#include #include #include using namespace std;const int MAX = 30;__int64 arr[MAX];int main(){ int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%I64d", &arr[i]); sort(ar

2016-03-16 20:39:25 482

原创 CodeForces 624A - Save Luke

因为tv1 + tv2 + d #include #include #include int main(){ double d, l, v1, v2; //scanf("%f%f%f%f", &d, &l, &v1, &v2); std::cin >> d >> l >> v1 >> v2; //printf("%.6lf\n", (l - d) / (v1 + v2));

2016-03-16 20:38:28 370

原创 CodeFOrces 625C - K-special Tables

k列的左边都是比第k列小的数,右边从左到右从上到下依次排就行了#include #include const int MAX = 505;int arr[MAX][MAX];int main(){ int n, k, t = 1; scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) { for (int j = 1

2016-03-15 22:58:08 700

原创 CodeForces 625B - War of the Corporations

字符串匹配#include #include #include const int MAX = 1e5 + 5;char arr1[MAX], arr2[35];int main(){ scanf("%s%s", arr1, arr2); int lenth1 = strlen(arr1), lenth2 = strlen(arr2), cnt = 0; for (int

2016-03-15 22:52:14 438

原创 CodeForces 625A - Guest From the Past

贪心#include int main(){ __int64 n, a, b, c; scanf("%I64d%I64d%I64d%I64d",&n, &a, &b, &c); __int64 res = 0; if (n >= b && b - c <= a) { res = (n - b) / (b - c) + 1; } printf("%I64d\n", res

2016-03-15 22:51:15 412

原创 LightOJ 1083 Histogram

单调栈。#include #include #include using namespace std;typedef long long ll;const int MAX = 3e4 + 5;ll arr[MAX];struct NODE{ ll l, val; NODE(ll tmp_l = 0, ll tmp_val = 0) : l(tmp_l), val(tm

2016-03-14 20:13:25 803

原创 CodeForces 622C Not Equal on a Segment

利用一个辅助数组存序号就行了。#include #include const int MAX = 2e5 + 5;int arr[MAX];int pre[MAX];int main(){ int n, q; scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) { scanf("%d", &arr[i]); i

2016-03-14 16:36:42 507

原创 CodeForces 622B - The Time

输出的技巧#include #include int main(){ int h, m; int num; scanf("%d:%d", &h, &m); scanf("%d", &num); m += num; h += m / 60; printf("%02d:%02d\n", h % 24, m % 60); return 0;}

2016-03-14 16:35:01 277

原创 CodeForces 622A Infinite Sequence

等差数列问题#include #include int main(){ __int64 n; scanf("%I64d", &n); __int64 i = 1; while (i * (1 + i) / 2 < n) { ++i; } __int64 tmp = (i - 1) * i / 2; //std::cout << tmp << std::endl;

2016-03-14 16:33:50 278

原创 LightOJ 1080 Binary Simulation

线段树模板题,开始用scanf("%c")一直错。。。#include #include #include const int MAX = 1e5 + 5;char arr[MAX];int res[3 * MAX];void update(int idx, int st, int ed, int q_st, int q_ed){ if (st == q_st && q_e

2016-03-12 16:16:52 604

原创 LightOJ 1112 Curious Robin Hood

全用int才对,树状数组。#include #include #include const int MAX = 1e5 + 5;int arr[MAX];int n, q;inline int lowbit(int x){ return x & (-x);}int update(int k, int num){ while (k <= n) { arr[k]

2016-03-12 11:32:07 418

转载 树状数组模板

模板int lowbit(int x){ return x & (-x);}void modify(int x,int add)//一维{ while(x<=MAXN) { a[x]+=add; x+=lowbit(x); }}int get_sum(int x){ int

2016-03-11 12:52:44 324

原创 CodeForces 628C - Bear and String Distance

贪心,先判断当前位置能否解决,不然就向下一个位置移动。#include #include const int MAX = 1e5 + 5;char arr1[MAX], arr2[MAX];int main(){ int n, k; scanf("%d%d", &n,&k); scanf("%s", arr1); for (int i = 0; arr1[i]; ++i)

2016-03-10 15:33:19 462

原创 CodeForces 628B New Skateboard

开始用O(n^2)的dp,然后tle了。#include #include #include //tle代码const int MAX = 3e5 + 5;char arr[MAX];int dp[MAX];int main(){ scanf("%s", arr + 1); int lenth = strlen(arr + 1), ans = 0; for (int i

2016-03-10 15:03:59 420

原创 CodeForces 628A Tennis Tournament

数学题,模拟。#include #include int main(){ int n, b, p, cnt = 0, p_num; scanf("%d%d%d", &n, &b, &p); p_num = n; while (n > 1) { int tmp = 2; for (int i = 1; ;++i) { //std::cout << tmp <<

2016-03-10 15:01:07 315

原创 lightOJ 1082 Array Queries

模板水题,套模板。。。#include #include const int MAX = 1e5 + 5;int arr[5 * MAX];int num;void update(int st, int ed, int id, int pos, int val){ if (st == pos && pos == ed) { arr[id] = val; return

2016-03-10 00:30:55 464

转载 CodeForces 629D Babaei and Birthday Cake

#include using namespace std;#define MohammadAmin main()#define mpair make_pair#define endl "\n"#define c_false ios_base::sync_with_stdio(false); cin.tie(0)#define pushb push_back#define push

2016-03-09 13:23:07 818

原创 CodeForces 629B Far Relative’s Problem

暴力#include int arr[2][367];int main(){ std::ios::sync_with_stdio(false); int n, st, ed; char sex; std::cin >> n; for (int i = 0; i != n; ++i) { std::cin >> sex >> st >> ed; if (sex ==

2016-03-08 23:37:14 351

原创 CodeForces 629A Far Relative’s Birthday Cake

组合数#include #include const int MAX = 105;char arr[MAX][MAX];int r[MAX], c[MAX];int C(int m, int n){ if (m < n) return 0; int res = 1; for (int i = 1; i <= n; ++i) { res *= (m + 1 - i

2016-03-08 23:35:43 321

原创 lightOJ 1214 Largest Division

#include #include #include #include const int MAX = 1e3 + 5;char arr[MAX];int main(){ int t, cas = 0; std::cin >> t; while (t--) { long long n, res = 0; std::cin >> arr >> n; int le

2016-03-08 19:04:20 420

原创 lightOJ 1186 Incredible Chess

#include #include const int MAX = 105;int arr1[105], arr2[105];int main(){ int t, cas = 0; std::cin >> t; while (t--) { int num; std::cin >> num; for (int i = 0; i != num; ++i) {

2016-03-08 13:14:30 872

原创 51nod 1091 线段的重叠

贪心,记录前面末尾坐标最长的点#include #include #include const int MAX = 5e4 + 5;struct NODE{ int st; int ed;}segment[MAX];bool comp(NODE a, NODE b){ return a.st == b.st ? a.ed < b.ed : a.st < b.st;}

2016-03-07 23:24:14 878

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除