- 博客(168)
- 收藏
- 关注
转载 【前向星】数据结构的实现
/* 前向星数据结构的实现 2014-4-1 21:36:48*/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>#define MAX 10000using namespace std;i...
2014-04-01 22:18:00
170
转载 【图形打印】菱形
/* 输入菱形的高度n(只能为奇数),输出图形 2014-4-1 18:38:57*/#include <stdio.h>#include <stdlib.h>int main(){ int n, i, j, cen; char ch[2]; do{ printf("请输入菱形的高度:"); scanf("%d", &n)...
2014-04-01 18:38:00
195
转载 NYOJ528 找球号(三)异或的运用
原题链接#include <stdio.h>int main(){ int n, t, x; while(scanf("%d", &n) == 1){ x = 0; while(n--){ scanf("%d", &t); x ^= t; } printf("%d\n", x); } return 0...
2014-04-01 11:33:00
164
转载 NYOJ30 Gone Fishing 贪心+枚举
原题链接之前WA了两次,都是由于没考虑到0的情况。样例输入2 湖的个数1 小时数10 1 最初5分钟捕鱼数2 5 每5分钟减少的鱼数2 跑路间隔时间*5 min4410 15 20 170 3 4 31 2 34410 15 50 300 3 4 31 2 30样例输出...
2014-04-01 11:17:00
184
转载 键盘输入输出
import java.io.*;public class Main{ public static void main(String[] args){ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); Stri...
2014-03-30 15:43:00
155
转载 【图形打印】等腰三角形
/* 输入n的值,输出由*组成的高为n的等腰三角形。 2014-3-29 18:46:34*/#include <stdio.h>int main(){ int n, i, j, k; char ch[2]; do{ printf("请输入想要打印的等腰三角形的高度n: "); scanf("%d", &n); for(i...
2014-03-30 13:49:00
678
转载 HDU1036 Average is not Fast Enough!
原题链接虽然是简单题,但是读懂题要花更长时间。。而且还有些细节要注意。#include <stdio.h>int main(){ int sectionNumber, t, ok; double relayDistance; char buf[20]; int teamNumber, teamSeconds, h, m, s;...
2014-03-30 13:22:00
124
转载 Java实现简单计算器
public class Main{ public static void main(String[] args){ if(args.length < 3){ System.out.println("Usage: java Test \"n1\" \"op\" \"n2\""); System.exit(-1); } double d1 = Do...
2014-03-27 20:33:00
134
转载 第一个Java程序
class Triangle{ int a = 10, b = 20, c = 25; int Zhouchang(){ return a + b + c; } double Area(){ double p = Zhouchang() / 2.0; return Math.sqrt(p * (p - a) * (p - b) * ...
2014-03-19 10:09:00
136
转载 NYOJ85 有趣的数
原题链接 #include <stdio.h>#include <math.h>int main(){ int m, n, x, y, t; scanf("%d", &m); while(m--){ scanf("%d", &n); x = 0; y = 1; for(int i = 1; (t = (...
2014-03-18 21:45:00
120
转载 NYOJ64 鸡兔同笼
原题链接#include <stdio.h>int main(){ int t, n, m,a ,b; scanf("%d", &t); while(t--){ scanf("%d%d", &n, &m); a = (m - 2 * n) / 2; //rabbit b = n - a; if(a <...
2014-03-17 17:22:00
113
转载 STL中的unique
去重函数。unique一般现需要对数组排序后再使用,返回值是不重复数组的哨兵位。#include <iostream>#include <algorithm>#include <vector>using namespace std;int main(){ int a[] = {1, 1, 1, 2, 2, 3, 4,...
2014-03-16 16:12:00
178
转载 NYOJ171 聪明的kk
原题链接#include <stdio.h>#include <algorithm>using namespace std;int A[21][21];int main(){ int n, m, i, j; while(scanf("%d%d", &n, &m) == 2){ for(i = 1; i <...
2014-03-16 08:47:00
100
转载 NYOJ18 The Triangle
原题链接#include <stdio.h>int A[101][101];int max(int a, int b){ if(a >= b) return a; return b;}int main(){ int n, i, j, temp; while(scanf("%d", &n) == 1){ for(i = ...
2014-03-16 08:46:00
115
转载 HDU1465 不容易系列之一
原题链接错排公式:当n个编号元素放在n个编号位置,元素编号与位置编号各不对应的方法数用D(n)表示,那么D(n-1)就表示n-1个编号元素放在n-1个编号位置,各不对应的方法数,其它类推.第一步,把第n个元素放在一个位置,比如位置k,一共有n-1种方法;第二步,放编号为k的元素,这时有两种情况:⑴把它放到位置n,那么,对于剩下的n-1个元素,由于第k个元素放到了位...
2014-03-15 18:17:00
111
转载 错排公式
当n个编号元素放在n个编号位置,元素编号与位置编号各不对应的方法数用D(n)表示,那么D(n-1)就表示n-1个编号元素放在n-1个编号位置,各不对应的方法数,其它类推.第一步,把第n个元素放在一个位置,比如位置k,一共有n-1种方法;第二步,放编号为k的元素,这时有两种情况:⑴把它放到位置n,那么,对于剩下的n-1个元素,由于第k个元素放到了位置n,剩下n-...
2014-03-15 17:42:00
246
转载 HDU2045 不容易系列之(3)—— LELE的RPG难题
原题链接当N=1、2、3时可以直接求出F[N]。当N>3时可得递推关系F[N]=F[N-1]+2*F[N-2];#include <stdio.h>__int64 a[51] = {0, 3, 6, 6};int main(){ int n; for(int i = 4; i != 51; ++i) a[i] = a...
2014-03-15 17:06:00
88
转载 HDU2050 折线分割平面
原题链接关键思路是:每增加N个交点就增加N+1部分平面。然后从最简单的情况开始找到递推关系。//a[n] = a[n-1] + 4 * (n - 1) + 1#include <stdio.h>#define MAX 10000 + 2__int64 a[MAX] = {1, 2, 7};int main(){ int t, i; ...
2014-03-15 15:34:00
114
转载 HDU1052 Tian Ji -- The Horse Racing
原题链接思路:先小到大排序,从最大的开始比较,如果An>Bn,则直接赢掉这局;如果An<Bn,则用A1输掉Bn;如果An==Bn,则比较A1和B1,若相等或A1小,则A1和Bn比,否则A1赢掉B1;#include <stdio.h>#include <stdlib.h>int a[1001], b[1001];int ...
2014-03-15 14:03:00
108
转载 NYOJ364 田忌赛马
原题链接思路:先小到大排序,从最大的开始比较,如果An>Bn,则直接赢掉这局;如果An<Bn,则用A1输掉Bn;如果An==Bn,则比较A1和B1,若相等或A1小,则A1和Bn比,否则A1赢掉B1;#include <stdio.h>#include <stdlib.h>int a[1001], b[1001];in...
2014-03-15 13:58:00
158
转载 NYOJ824 Greedy Mouse
原题链接郁闷,WA了3次,好在最终找到了原因,qsort的cmp函数有问题,对于浮点数,比较的时候一定要注意。#include <stdio.h>#include <stdlib.h>struct Node{ int x, y; double rate;};int cmp(const void *a, const void *b){...
2014-03-15 01:20:00
125
转载 NYOJ891 找点
原题链接思路:将每个区间段按照右端点从小到大排序,count赋值为n,从第一个开始以右端点为基准判断是否在接下来的区段中间,若在则--count。#include <stdio.h>#include <stdlib.h>struct Node{ int x, y;};Node arr[101];int cmp(const vo...
2014-03-14 23:46:00
127
转载 NYOJ915 +-字符串
原题链接主要思路:从左到右,逐个比较,若有不同,标记此不同地点,并向右搜寻首个相同点,从该点开始挨个与左边位置交换并统计交换次数。#include <stdio.h>#include <string.h>#define MAX 5000 + 2char str[MAX], str2[MAX];int find(int i){ int...
2014-03-13 20:57:00
119
转载 NYOJ47 过河问题
原题链接思路:首先将最慢的两个弄过去。两种方案:1、A1带A2过去,A1回来,An带An-1过去,A2回来。用时T=A1+An+2*A2;2、A1带An过去,A1回来,A1带An-1过去,A1回来。用时T=An+An-1+2*A1;采用两者中用时较少的方案#include <stdio.h>#include <stdlib.h>...
2014-03-12 16:36:00
156
转载 HDOJ1050 Moving Tables
原题链接#include <stdio.h>struct Node{ int begin, end;};Node a[201];int p[401];int main(){ int t, n, i, temp, count, j; scanf("%d", &t); while(t--){ scanf("%d", &...
2014-03-11 22:33:00
88
转载 NYOJ56 阶乘因式分解(一)
原题链接思路:比如说13的阶乘中有多少个3.13!=1*2*3*...*6*...9*...12;其中有多少个数能被3整除呢?答案是13/3=4个。但是答案却是5,为什么,因为9里面有2个3所以是4个.若是100!里面有多少个5?首先看里面有多少个数能被5整除,答案是100/5=20;再看有多少个数能被5*5整除,答案是100/25=(100/5)上面的结...
2014-03-11 21:21:00
114
转载 HDOJ1205 吃糖果
原题链接注意要用__int64存和。//2014-3-11 20:31:42#include <stdio.h>int main(){ int t, n, max, a; __int64 s; scanf("%d", &t); while(t-- && scanf("%d", &n)){ s = max = 0...
2014-03-11 20:38:00
104
转载 HDOJ2035 人见人爱A^B 二分法
原题链接//二分法2014-3-11 19:10:15#include <stdio.h>int f(int a, int b){ if(b == 1) return a; int s = f(a, b / 2); if(b & 1) return s * s * a % 1000; else return s * s % 1000...
2014-03-11 19:16:00
96
转载 HDOJ1061 Rightmost Digit
原题链接很经典的一道题,开始想着用二分法,结果超时,后来发现了规律,就搞定啦。//找规律2014-3-11 18:40:19#include <stdio.h>#include <string.h>char *sam[] = {"0", "1", "2486", "3971", "46", "5", "6", "7931", "8426", ...
2014-03-11 18:52:00
126
转载 HDOJ1021 Fibonacci Again
原题链接//2014-3-11 09:16:50#include <stdio.h>#define MAX 1000000int a[MAX] = {1, 2};int main(){ int n; for(n = 2; n != MAX; ++n) a[n] = (a[n - 1] + a[n - 2]) % 3; while(s...
2014-03-11 09:20:00
136
转载 HDOJ1019 Least Common Multiple
原题链接最小公倍数等于两数之积除以最大公约数。//2014-3-11 09:03:09#include <stdio.h>int gcd(int a, int b){ int t; while(b){ t = a % b; a = b; b = t; } return a;}int main(){ int t, n, a, s...
2014-03-11 09:10:00
113
转载 HDOJ1017 A Mathematical Curiosity
原题链接注意输出格式,每一组的case都要重新开始计数。//模拟//2014-3-11 08:19:16#include <stdio.h>int main(){ int t, n, m, a, b, count, time; scanf("%d", &t); while(t--){ time = 1; ...
2014-03-11 08:51:00
100
转载 NYOJ2 括号配对问题
原题链接#include <stdio.h>char buf[10001];int main(){ int t; char *p, ch; scanf("%d\n", &t); while(t--){ buf[0] = getchar(); p = buf + 1; while((ch = getchar()) != '\...
2014-03-11 08:43:00
74
转载 HDOJ1014 Uniform Generator
原题链接问题最后转化成求两个数的最大公约数,如果为1就YES.#include <stdio.h>int main(){ int step, mod, t; while(scanf("%d%d", &step, &mod) == 2){ printf("%10d%10d", step, mod); while(mod){ ...
2014-03-11 07:59:00
105
转载 HDOJ1013 Digital Roots
原题链接略坑的一道题。#include <stdio.h>char str[1000];int f(int n){ int s = 0; while(n){ s += n % 10; n /= 10; } return s;}int main(){ int n, s; ...
2014-03-10 22:32:00
112
转载 NYOJ852 蛇形填数(二)
原题链接#include <stdio.h>#include <string.h>#define MAX 1001int a[MAX][MAX];int main(){ int t, n, max, count, i, j; scanf("%d", &t); while(t--){ scanf("%d", &...
2014-03-09 00:07:00
74
转载 NYOJ871 比赛 stable_sort
原题链接stable_sort函数的用法。#include <iostream>#include <algorithm>#include <string>#include <vector>using namespace std;struct Node{ int num, sco; string name;}...
2014-03-08 23:03:00
85
转载 NYOJ864 统计
原题链接这个OJ的int不是32位的,所以坑了不少人,换成unsigned long long就行了。#include <stdio.h>int main(){ unsigned long long t, n, a, b, d, i, j, oka; scanf("%lld", &t); while(t--){ scanf("%lld",...
2014-03-08 22:43:00
85
转载 NYOJ664 数字整除
原题链接(a-b)%c = (a%c - b%c)%c#include <stdio.h>#include <string.h>char str[105];int main(){ int c, len, a, i; while(scanf("%s", str), str[0] != '0'){ len = strlen(str)...
2014-03-08 22:04:00
139
转载 NYOJ663 弟弟的作业
原题链接#include <stdio.h>//#include <stdlib.h>int main(){ int a, b, c, count = 0; char ch, sign, s[5]; while(scanf("%d%c%d=%s", &a, &sign, &b, s) != EOF){ i...
2014-03-08 12:51:00
63
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人