- 博客(46)
- 收藏
- 关注
原创 1064. Complete Binary Search Tree (30)
1064. Complete Binary Search Tree (30)#include <stdio.h>#include <stdlib.h>int n,cbst[1001],a[1001],cur;int comp(const void*a,const void*b){ return *((int*)a)-*((int*)b);}void creatCBST(int *
2016-11-30 19:06:05 264
原创 1099. Build A Binary Search Tree (30)
1099. Build A Binary Search Tree (30)#include <stdio.h>#include <stdlib.h>struct bst{ int left,right; int data;}node[101];int a[101],cur=0;struct bst *queue[101];int front,rear;int comp
2016-11-30 17:22:46 245
原创 1078. Hashing (25)
1078. Hashing (25) 注意:题目要求用二次探测法(Quadratic probing)解决冲突#include <stdio.h>#include <malloc.h>#include <math.h>int hash[10010];int isprime(int n){ if(n==1) return 0; if(n==2)
2016-11-30 08:47:42 288
原创 1094. The Largest Generation (25)
1094. The Largest Generation (25)#include <cstdio>#include <vector>#include <queue>int main(){ std::vector<std::vector<int>> v(100); int n,m; scanf("%d %d",&n,&m); while(m--) {
2016-11-30 00:40:21 308
原创 1074. Reversing Linked List (25)
1074. Reversing Linked List (25)#include <stdio.h>struct node{ int address; int data; int next;}node[100001];struct node *stack[100001];struct node *queue[100001];int top,front,rear;i
2016-11-29 23:44:16 337
原创 1083. List Grades (25)
1083. List Grades (25)#include <stdio.h>#include <stdlib.h>struct record{ char name[12]; char id[12]; int score;}s[1000];int comp(const void*a,const void*b){ return ((struct recor
2016-11-29 23:34:24 242
原创 1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25)#include <cstdio>#include <vector>#include <cmath>int maxheight=-1,find=0;void dfs(int k,int h,std::vector<std::vector<int>> &v){ if(maxheight<h) {
2016-11-29 23:14:04 274
原创 1097. Deduplication on a Linked List (25)
1097. Deduplication on a Linked List (25)#include <stdio.h>#include <stdlib.h>struct node{ int address; int data; int next;}node[100001];struct node *aqueue[100001],*bqueue[100001];in
2016-11-29 21:52:18 369
原创 1025. 反转链表 (25)
给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。输入格式:每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点总个数正整数N(<= 105)、以及正整数K(<=N),即要求反转的子链结点的个数。结点的地址是5位非
2016-11-28 16:11:35 482
原创 C语言函数传递指针参数的问题
一个问题是,我们想用一个函数来对函数外的变量v进行操作,比如,我想在函数里稍微改变一下这个变量v的值,我们应该怎么做呢?又或者一个常见的例子,我想利用swap()函数交换两个变量a,b的值,我们应该怎么做呢(好吧,博主是觉得这个问题十分经典)。如果你真的理解C语言中【函数】这个工具的本质,我想你稍微仔细的思考一下,可能就不会来查看博主的这篇文章,对函数来说,它所传递的任何参数仅仅是原来参数的一...
2016-11-28 12:14:18 42271 19
原创 1026. Table Tennis (30)
1026. Table Tennis (30) 注:最后一个测试用例没过,只有29分,以后再看。。#include <stdio.h>#include <stdlib.h>struct record{ int atime;//arrive time int utime;//use time:p int isvip;//is vip? int wtime;//w
2016-11-27 14:23:13 544
原创 1044. 火星数字(20)
火星人是以13进制计数的:地球人的0被火星人称为tret。地球人数字1到12的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。火星人将进位以后的12个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。 例如地球人的数字“29”
2016-11-27 00:14:10 763
原创 1052. 卖个萌 (20)
萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:左手[右手]现给出可选用的符号集合,请你按用户的要求输出表情。输入格式:输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号[]内。题目保证每个集合都至少有一个符号,并不超过10个符号;每个符号包含1到4个非空字符。之后一行给出一个正整数K,为用户请求的个数。随后K行,
2016-11-27 00:08:15 417
原创 1054. 求平均值 (20)
本题的基本要求非常简单:给定N个实数,计算它们的平均值。但复杂的是有些输入数据可能是非法的。一个“合法”的输入是[-1000,1000]区间内的实数,并且最多精确到小数点后2位。当你计算平均值的时候,不能把那些非法的数据算在内。输入格式:输入第一行给出正整数N(<=100)。随后一行给出N个正整数,数字间以一个空格分隔。输出格式:对每个非法输入,在一行中输出“ERROR: X is not a le
2016-11-26 22:31:04 437
原创 1058. 选择题(20)
批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。输入格式:输入在第一行给出两个正整数N(输出格式:按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余
2016-11-26 21:41:25 545
原创 1022. Digital Library (30)
1022. Digital Library (30)#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 80+1struct book{ char id[8]; char title[N]; char author[N]; char keywords[100]; char
2016-11-25 19:43:38 321
原创 C语言字符串函数总结(部分常见字符串函数)
1.atoi()函数:将字符串转换成整数 头文件:#include < stdlib.h > 定义函数:int atoi(const char *nptr); 函数说明:atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时(‘\0’) 才结束转换,并将结果返回。 返回值:返回转换后的整型数 注:类似的还有atof()
2016-11-25 17:40:15 428
原创 1018. Public Bike Management (30)
1018. Public Bike Management (30) 思路:用dijkstra算法求出并用path记录多条路径,然后dfs筛选最优路径 注意:send和back的记录;在沿途中,如果count<0的话,说明需要send,比如0->4,4,7,从原点出发,经过4,为使其perfect,需要send,最终结果为,send=2,back=2(并不是send和back中一定有一个为0)#i
2016-11-20 13:41:54 970
原创 1014. Waiting in Line (30)
1014. Waiting in Line (30) 题目较简单;设置一个队列queue[N]数组,记录用户所用时,设置一个服务窗口service[n][m]二维数组,用于每次记录时间,同时每次累加用户用时后将结果存到ans[N]数组即可;#include <stdio.h>void InitService(int service[][11],int n){ for(int i=0;i
2016-11-18 19:32:22 511
原创 1067. Sort with Swap(0,*) (25)
1067. Sort with Swap(0,*) (25)#include <stdio.h>#define N 100000+1void swap(int*a,int*b){ int temp=*a; *a=*b;*b=temp;}int FindPosition(int a[],int n,int s){ int i; for(i=s;i<n;++i
2016-11-17 20:28:02 353
原创 1063. Set Similarity (25)
1063. Set Similarity (25) 思路是很简单的:对集合里的元素进行排序,两相比较即可; 注意到集合里可能会有重复的数, 需要排除重复数据,而题目给了数据的范围[0,10^9],所以,对集合里重复的数据进行排除就很简单了,只需遍历一次,把相同的数赋值为-1(不可能的输入),然后再比较就行了#include <stdio.h>#include <stdlib.h>#defin
2016-11-17 17:20:27 373
原创 1062. Talent and Virtue (25)
1062. Talent and Virtue (25) 乙级:1015. 德才论 (25)
2016-11-15 14:49:34 370
原创 1060. Are They Equal (25)
1060. Are They Equal (25) 思路其实很简单的,找到小数点和非0的位置,指数值就是小数点的位置减去非0位的位置(如果为负,则需要加1) 注意:0的测试数据可能为0.00000和0.0或者0等#include <stdio.h>#include <string.h>int FindPoint(char s[]){ int len=strlen(s),i;
2016-11-15 14:40:16 353
原创 1104. Sum of Number Segments (20)
1104. Sum of Number Segments (20) 乙级:1049. 数列的片段和(20)
2016-11-14 16:09:39 365
原创 1093. Count PAT's (25)
1093. Count PAT’s (25)#include<stdio.h>#include<string.h>#define N 100005int main(){ long long count=0; int i=0,k=0,p=0,t=0,b[N],a[N],n; char s[N],ch; while((ch=getchar())!='\n')
2016-11-14 16:04:27 303
原创 1096. Consecutive Factors (20)
1096. Consecutive Factors (20)#include <stdio.h>#include <math.h>int main(){ int n; scanf("%d",&n); int key=sqrt((double)n); int s,maxlen=0; for(int i=2;i<=key;++i) {
2016-11-14 15:33:41 371
原创 1100. Mars Numbers (20)
1100. Mars Numbers (20) 重写了乙级的代码#include <stdio.h>#include <string.h>int main(){ char low[13][5]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"}; char high[
2016-11-14 13:34:51 592
原创 1056. Mice and Rice (25)
1056. Mice and Rice (25)#include <stdio.h>#include <malloc.h>int FindMaxi(int record[],int a[],int begin,int end){ int max=record[a[begin]],i=a[begin]; while(begin<end) { if(reco
2016-11-09 20:22:26 340
原创 1059. Prime Factors (25)
1059. Prime Factors (25)#include <stdio.h>#include <math.h>long int a[1000][2];int main(){ long int n,m,i=2; int k=0; scanf("%ld",&n); m=n; if(n==1) { printf("1=1");
2016-11-09 14:45:09 290
原创 1055. The World's Richest (25)
1055. The World’s Richest (25)#include <stdio.h>#include <stdlib.h>#include <string.h>struct record{ char name[10]; int age; int worth;}s[100001];int comp(const void*a,const void*b){
2016-11-06 10:45:38 409
原创 排序算法之选择排序<Selection_Sort>及其C语言代码实现
概述 一个选择排序是一种简单排序,它的排序思路是:每次从未排序的序列中选出一个最小值,并把它放在已排好序的序列的序尾。这样就形成了一个有序序列(从小到大)。 时间复杂度:o(n^2) 核心代码:void Selection_Sort(int a[],int n){ int i; for(i=0;i<n;++i) { int j=ScanForMin(a
2016-11-06 10:08:45 4280
原创 排序算法之希尔排序<Shell_Sort>及其C语言代码实现
概述 希尔排序(Shell Sort)是插入排序的一种。也称缩小增量排序,是直接插入排序算法的一种更高效的改进版本。希尔排序是非稳定排序算法。该方法因DL.Shell于1959年提出而得名。 希尔排序设定了一个增量d,每次插入排序使相距为d的元素排成一个有序列,然后缩小增量,继续插入排序,最后一次d=1,排序完成 最坏时间复杂度:o(n^2) 核心代码:void Shell_Sort(in
2016-11-06 09:46:50 5744
原创 排序算法之插入排序<Insertion_Sort>及其C语言代码实现
概述 一个插入排序是另一种简单排序,它的思路是:每次从未排好的序列中选出一个元素插入到已排好的序列中。它的算法步骤可以大致归纳如下: 1. 从未排好的序列中选出一个元素,并把它赋值给temp变量; 2. 从排好的序列中,依次与temp进行比较,如果元素比temp大,则将元素后移(实际上放置temp的元素位置已经空出) 3. 直到找到一个元素比temp小, 将temp放入该位置; 时间复杂
2016-11-06 08:57:52 14610
原创 排序算法之冒泡排序<Bubble_Sort>及其C语言代码实现
概述 冒泡排序是一种相对简单的排序,它每次比较相邻的两个元素,如果前者大于后者,则交换< swap >这两个元素(从小到大排序),这样每一趟比较就把大的元素沉入最后,形象的称之为“冒泡”,每走一趟,实际上最尾的元素已经排好。 时间复杂度:o(n^2) 核心代码实现:void Bubble_Sort(int a[],int n)//冒泡排序{ int i,j; for(i=n-
2016-11-05 23:00:47 5985
原创 1051. Pop Sequence (25)
1051. Pop Sequence (25)#include <stdio.h>int main(){ int stack[1000],top; int m,n,k; scanf("%d %d %d",&m,&n,&k); while(k--) { int v=1,i,e; top=0; for(i=0;i
2016-11-05 14:32:22 374
原创 1048. Find Coins (25)
1048. Find Coins (25)#include <stdio.h>#include <stdlib.h>int a[100001];int comp(const void*a,const void*b){ return *((int *)a)-*((int *)b);}int main(){ int n,m,i; scanf("%d %d",&n,&
2016-11-05 13:45:14 282
原创 1047. Student List for Course (25)
1047. Student List for Course (25)#include <stdio.h>#include <string.h>#include <stdlib.h>struct list{ char student[1000][5]; int top;}s[2501];int comp(const void*a,const void*b){ re
2016-11-05 13:11:50 315
原创 1044. Shopping in Mars (25)
1044. Shopping in Mars (25)#include <bits/stdc++.h>using namespace std;int A[100000+1],n,m,values=0,low=1,high=0;int main(){ scanf("%d %d",&n,&m); for(int i=1;i<=n;++i) ...
2016-11-05 10:58:43 282
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人