- 博客(189)
- 收藏
- 关注
原创 POJ 3114 Spy Communication (强连通分量tarjan + SPFA)
#include #define MAX_CITIES 555#define MAX_AGREEMENTS (MAX_CITIES * MAX_CITIES)#define INF (1 << 30)#define QUEUE_SIZE 200000000int numOfCities;int numOfAgreements;struct AGREEMENT{ int ad
2015-09-24 14:10:36 328
原创 POJ 2186 Superstar Cow
//refer to http://www.tuicool.com/articles/AZ77Fv#include #define MAX_COWS 10001#define MAX_PAIRS 50001int numOfCows;int numOfPairs;typedef struct { int adjaVertex; int nextEdgeNum;} edg
2015-09-24 14:08:46 298
原创 POJ 3614 Sun Bathing (贪心)
#include#include#define MAX 2501int cows;int bottles;int minSPF[MAX];int maxSPF[MAX];int lotionSPF[MAX];int covers[MAX];struct node{ int SPF; node *pNext;};node *head =
2015-09-24 12:24:07 311
原创 POJ 2823 Sliding Window (单调队列)
#includeint farms, fields, paths, wormholes;typedef struct{ int from; int to; int seconds;}edge;edge edges[5201];int numOfEdges;int time[1001];void addEdge(int from, int to,
2015-09-24 11:55:50 341
原创 POJ 3259 Back to the past
#includeint farms, fields, paths, wormholes;typedef struct{ int from; int to; int seconds;}edge;edge edges[5201];int numOfEdges;int time[1001];void addEdge(int from, int to,
2015-09-24 11:52:12 241
原创 POJ 1382 Cover The Island
#include #include #define MAX 1001int islands;int radius;int x[MAX];int y[MAX];double left[MAX];double right[MAX];int radars;double radarX;int partition(int left, int right
2015-09-24 11:42:48 317
原创 POJ 1154 Letter game (DFS)
#include #define MAX 22int rows;int columns;char board[MAX][MAX]; //up down left rightint dirs[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};int visitedLetters[26];
2015-09-24 11:39:43 249
原创 POJ 2531 Network revenger (DFS)
#include #define MAX 21int nodes;int traffic[MAX][MAX];int subsetA[MAX];int subsetB[MAX];int sizeOfA;int sizeOfB;int maxSum;void devide(int currentNode){ if (currentNode == nodes){
2015-09-24 11:37:01 244
原创 URAL 1208 Legendary Teams Contest (DFS)
#include #define NAMES_IN_TEAM (3 + 1)#define MAX_TEAMS (18 + 1)#define MAX_LETTERS (20 + 1)int numOfTeams;char namesInTeam[MAX_TEAMS][NAMES_IN_TEAM][MAX_LETTERS];int isTeamVisited[MAX_TEAMS];i
2015-09-24 11:27:21 276
原创 URAL 1643 Attack of the Dark Fortress (BFS)
#include #define INF (1 << 31 - 1)#define MAX (100 + 1)#define CA 1#define GA 2int rows, columns;char map[MAX][MAX];int rowOfCA, columnOfCA;int rowOfGA, columnOfGA;int rowOfFortress, columnOf
2015-09-24 11:24:58 291
原创 URAL 1329 Galactic History (DFS)
#include#define MAX (40000 + 1)int numOfMilestones;typedef struct{ int id; int next;}NODE;NODE sonArray[MAX];//used as adjacent listint sonNum;int headArray[MAX];int root;typedef stru
2015-09-24 11:23:17 297
原创 URAL 1005 Stone Pile (DFS)
#include #define ABS(x) ( (x) > 0 ? (x) : -(x) )#define INF (1 << 31 - 1)#define MAX_STONES (20 + 1)#define MAX_WEIGHT (100000)int numOfStones;int weights[MAX_STONES];int totalWeigh;int minD
2015-09-24 11:19:35 400
原创 URAL 1280 Topological Sorting
#include#define MAX_SUBJECTS (1000 + 1)#define MAX_LIMITATIONS (100000 + 1)int before[MAX_LIMITATIONS];int after[MAX_LIMITATIONS];int orders[MAX_SUBJECTS];int main(){ int numOfSubjects,
2015-09-24 11:17:06 502
原创 POJ 3414 Pots (BFS)
#include #define MAX 101int volumnOfPotA, volumnOfPotB, litersToYield;int stateVisited[MAX][MAX];typedef struct { int litersInA; int litersInB; int operation; int pre
2015-09-24 11:13:48 328
原创 URAL 1080 Map Coloring (BFS)
#include#define MAX_COUNTRIES 99struct CONNECTION{ int connectedCountry; int next;};int color[MAX_COUNTRIES];CONNECTION connectionNumArray[MAX_COUNTRIES * MAX_COUNTRIES];//used as ad
2015-09-24 11:12:03 483
原创 URAL 1263 Elections
#include#define MAX_CANDIDATES 10000#define MAX_ELECTORS 10000float voteArray[MAX_CANDIDATES + 1];int main(){ float numOfCandidates, numOfElectors; scanf("%f %f", &numOfCandidates, &nu
2015-09-24 11:07:37 327
原创 URAL 1753 Bookshelf (三分答案)
#include #include #define PRECISION 1e-10double PI = acos(-1.0);int bookshelfHeight, bookHeight, bookshelfLength;//agnle是书本和书架的夹角double calculateResult(double angle){ return bookHeight * cos(
2015-09-24 10:33:19 760
原创 POJ 3273 Monthly Expense (二分答案)
#include #define MAX_DAYS 100000int numOfDays, numOfPeriods;int dollersArray[MAX_DAYS + 1];int main(){ scanf("%d%d", &numOfDays, &numOfPeriods); int minLimit = 0; int maxLimit = 0; int day;
2015-09-23 17:17:45 363
原创 POJ 1064 Cable master (二分答案)
#include #define MAX_CABLES 10000#define MAX_LENGTH 1e5int numOfCables, numOfPieces;int lengthArray[MAX_CABLES + 1];int main(){ scanf("%d%d", &numOfCables, &numOfPieces); int cable; int righ
2015-09-23 15:51:52 405
原创 8种排序
#includevoid printArray(int array[], int size){ int i; for (i = 0; i < size; i++) printf("%d ", array[i]); printf("\n");}void swap(int *a, int *b){ int temp = *a; *a = *b; *b = temp;}v
2015-09-23 14:07:42 327
原创 二分搜索
int binarySearchValueIteratively(int array[], int size, int value){ int left = 0; int right = size - 1; //为了防止(left + right)溢出,所以先算(right - left),并用移位操作加速,注意">>"优先级很低 int mid = left + ( (right -
2015-09-23 10:01:59 320
原创 POJ 2456 Aggressive cows (二分 + 贪心)
#include int numOfStalls, numOfCows;int position[100001];int heapSize;void maxHeapify(int parent){ int largest = parent; int left = parent << 1; if (left position[largest]) largest = left;
2015-09-22 19:23:58 412
原创 URAL 1495 One-two, One-two 2 (BFS)
#include int N;typedef struct Node{ char num[32]; int mod;}Node;Node queue[1000000];int visited[1000001];char *str = "012";int head, tail;int strLen(char *str){ char *p = str; while (*p
2015-09-22 14:08:18 553
原创 URAL 1009 K-based Numbers (DFS)
#include int numOfDigits, base;int result;void isValid(int digits, int preDigit){ if (digits > numOfDigits){ result++; return; } int digit; for (digit = 0; digit < base; digit++){ if (
2015-09-22 09:50:02 326
原创 URAL 1009 K-based Numbers (DP动态规划)
#include int numOfDigits, base;//result[digits]表示N为digits时的有多少个有效数字int result[18];int main(){ scanf("%d %d", &numOfDigits, &base); //最高位非0 result[1] = base - 1; result[2] = (base - 1) * b
2015-09-22 09:48:07 315
原创 USACO 1.5 Number Triangles (DP动态规划)
#include #define DEBUG 1#define TESTCASES 9#define MAX 1000#define BIGGER(x, y) ( (x) > (y) ? (x) : (y) )int numOfRows;int triangle[MAX + 1][MAX + 1];int main(){#if DEBUG int testCase; for
2015-09-21 22:54:01 344
原创 USACO 1.4 Mother's Milk (枚举 + DFS)
#include #define DEBUG 0#define TESTCASES 9#define MAX_CAPACITY 20int capacity[4];int visited[MAX_CAPACITY + 1][MAX_CAPACITY + 1];int num;void pour(int state[4]){ int from, to; for (from =
2015-09-21 22:07:09 419
原创 POJ 2533 Longest Ordered Subsequence (DP动态规划)
#include int seq[1001];//lenOfLOSWithTai[i]表示已seq[i]为结尾的最长有序子序列的长度int lenOfLOSWithTail[1001];//length of longest ordered sequence with tail int main(){ int lenOfSeq; scanf("%d", &lenOfSeq); i
2015-09-21 16:35:42 407
原创 URAL 1210 Kind Spirits (DP动态规划)
#include #define MAX_LEVELS 30#define MAX_PLANETS 31#define MAX_PAY 1e7int numOfLevels;int minPay[MAX_LEVELS][MAX_PLANETS];int main(){ scanf("%d", &numOfLevels); int level; for (level = 1;
2015-09-21 16:17:38 430
原创 URAL 1119 Metro (DP动态规划)
#include #define MAX 1000#define INF 1e6#define MIN(x, y) ( (x) < (y) ? (x) : (y) )int WEsize, SNsize;int numOfCrosses;int x, y;float shortestRoute[MAX + 1][MAX + 1];int main(){ scanf("%d%d
2015-09-21 13:37:31 344
原创 USACO 1.4 Arithmetic Progressions (堆排序 + 枚举)
#include #define DEBUG 1#define TESTCASES 9#define MAX 250int lenOfProgressions;int upperBound;//双平方数的哈希int isBisquare[2 * MAX * MAX + 1];int arrayOfBisquares[2 * MAX * MAX + 1];int numOfBis
2015-09-20 21:03:30 294
原创 USACO 1.4 Arithmetic Progressions (暴力搜索)
#include #define DEBUG 1#define TESTCASES 9#define MAX 250int lenOfProgressions;int upperBound;//双平方数的哈希int isBisquare[2 * MAX * MAX + 1];int main(){#if DEBUG int testCase; for (testCase
2015-09-20 19:37:04 287
原创 USACO 1.4 The Clocks (位操作+枚举+BFS)
#include #define DEBUG 1#define TESTCASES 9#define CLOCKS 9#define MOVES 9#define STATES 300000 //4^9 < 3000000int queue[STATES];int head, tail;//既可以记录前个状态,又可以而作状态被访问过的标记int pre[STATES];int
2015-09-20 09:52:04 565 1
原创 USACO 1.4 The Clocks (位操作+枚举+DFS)
#include #define DEBUG 1#define TESTCASES 9#define INF (1 << 31 - 1)#define CLOCKS 9#define MOVES 9int arrayOfMoves[MOVES + 1] = {0, 18911232, 19136512, 2363904, 16810048, 2134536, 262657, 3693
2015-09-19 21:52:40 491
原创 USACO 1.4 The Clocks (暴力枚举)
#include #define DEBUG 0#define TESTCASES 9#define CLOCKS 9#define MOVES 9#define FOR(index, size) for ((index) = 0; (index) < (size); (index)++)int initialState[CLOCKS];int arrayOfMove[MOVES][
2015-09-19 17:51:55 561 1
原创 USACO 1.3 Ski Course Design
#include#define MAX_HILLS 1000#define MAX_ELEVATION 100int numOfHills;int elevation[MAX_HILLS + 1];int minCost = (1 << 31 - 1);int main(){ scanf("%d", &numOfHills); int maxHeight = 0; int h
2015-09-19 16:56:05 292
原创 USACO 1.3 Wormholes (枚举+DFS+模拟)
/*首先要枚举所有可能的配对情况,当完成所有虫洞的配对后,再检查有没有环,注意要将每次枚举求得的结果(1代表有环,0代表无环)累加并返回*/#include#define MAX_WORMHOLES 12int numOfWormholes;int x[MAX_WORMHOLES + 1];int y[MAX_WORMHOLES + 1];//nextWormhole[curren
2015-09-19 13:29:10 668 1
原创 USACO 1.3 Combination Lock
#include#define GET_ABS(x) ( (x) > 0 ? (x) : -(x) )int maxNum;int FJCombination[4];int masterCombination[4];int settings[4];int result;int isCloseEnough(int combination[]){ int dial; for (di
2015-09-19 08:55:03 313
原创 USACO 1.1 Greedy Gift Givers
/*ID: bpsaman1LANG: CTASK: gift1*/#include #define PERSONS 10#define LEN_NAME 14int numOfPersons;typedef struct PERSON{ char name[LEN_NAME + 1]; int monney;}Person;Person arrayOfPerson[
2015-09-18 22:51:56 272
原创 USACO Section 1.1 Your Ride Is Here
Your Ride Is HereIt is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick u
2015-09-17 23:52:59 314
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人