- 博客(15)
- 资源 (1)
- 收藏
- 关注
原创 题目1510:替换空格
#include #include char str[1000000]; int main(){ while(gets(str)){ int count=0,i,j; int len=strlen(str); for(i=0;i<len;i++){ if(str[i]==' ') count++; }
2014-07-16 17:40:11
312
原创 剑指offer 1384 二维数组中的查找
#include int binary_search(int a[],int l,int r,int t){ int begin=l; int end=r; while(begin<=end){ int mid=(begin+end)/2; if(t==a[mid]) return 1; else if(t<a[mid])
2014-07-16 16:22:32
331
原创 hdu 1425 sort
http://acm.hdu.edu.cn/showproble#include int m,n; const int N=1000005; int a[N]; int quicksort(int l,int r){ if(l<r){ int low=l; int high=r; int x=a[l]; while(low<high){ while(lo
2014-06-18 22:55:10
359
原创 hdu 1060 Leftmost Digit
http://acm.hdu.edu.cn/showproblem.php?pid=1060 m=n^n;两边同取对数,得到,log10(m)=n*log10(n);再得到,m=10^(n*log10(n)); 然后,对于10的整数次幂,第一位是1,所以,第一位数取决于n*log10(n)的小数部分 #include #include int main() {
2013-07-26 19:44:40
357
原创 hdu 1286 找新朋友
http://acm.hdu.edu.cn/showproblem.php?pid=1286 #include #include int main() { int a[40000],T,i; while(scanf("%d",&T)!=EOF){ while(T--){ memset(a,0,sizeof(a)); int n,count=0;
2013-07-26 15:46:21
374
原创 hdu 1215 七夕节
http://acm.hdu.edu.cn/showproblem.php?pid=1215 主要问题在于容易超时。。。 #include #include int main() { int T,m; while(scanf("%d",&T)!=EOF){ while(T--){ scanf("%d",&m); int t,sum=1;
2013-07-14 22:59:49
429
原创 hdu 1722 Cake
点击打开链接 开始没什么思路,看了别人的博客才豁然开朗,有思路代码就很简单了,把蛋糕分成p块,再拼在一起分成q块,分成p块需切p刀,分成p块需切p刀,拼在一起则需减去公共部分,即需切p+q-gcd(p,q)刀 #include int gcd(int p,int q) { int r,t=0; if(p<q){ t=p; p=q; q=t; } r=p%
2013-07-14 21:00:02
382
原创 hdu 2138 How many prime numbers
http://acm.hdu.edu.cn/showproblem.php?pid=2138 #include #include int isprime(int m) { for(int i=2;i<=sqrt(m);i++) if(m%i==0) return 0; return 1; } int main() { int T,a; while(scanf
2013-07-14 19:50:24
420
原创 hdu 1108 最小公倍数
http://acm.hdu.edu.cn/showproblem.php?pid=1108 import java.util.Scanner; public class Hd { public static void main(String args[]) { int m,n,a,b; Scanner reader=new Scanner(System.in);
2013-07-13 23:39:32
473
转载 01背包问题 动态规划
动态规划是用空间换时间的一种方法的抽象。其关键是发现子问题和记录其结果。然后利用这些结果减轻运算量。 比如01背包问题。 /* 一个旅行者有一个最多能用M公斤的背包,现在有N件物品, 它们的重量分别是W1,W2,...,Wn, 它们的价值分别为P1,P2,...,Pn. 若每种物品只有一件求旅行者能获得最大总价值。 输入格式: M,N W1,P1 W2,P2 ......
2013-06-24 19:25:22
585
原创 hdu 1157 Who's in the Middle
http://acm.hdu.edu.cn/showproblem.php?pid=1157 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6012 Accepted Submission(s): 3003 Problem
2013-03-19 22:16:13
400
转载 sort函数
头文件: #include using namespace std; 1 默认的sort函数是按升序排列 sort(a,a+n);//两个参数分别为待排数组的首地址和尾地址 2 可以自己写一个cmp函数,按特定意图排序 int cmp(const int &a,const int &b){ if(a>b) return 1; els
2013-03-19 21:49:45
623
原创 HDU 1197 Specialized Four-Digit Numbers
http://acm.hdu.edu.cn/showproblem.php?pid=1197 #include int change(int n,int base) { int a=0; while(n) { a+=n%base; n=n/base; } return a; } int main() { int sum10,sum12,sum16,i; for(i=2992
2013-02-05 11:34:06
272
原创 hdu 1219 AC Me
http://acm.hdu.edu.cn/showproblem.php?pid=1219 #include #include char s[100001]; int a[26]; int main() { int i; while(gets(s)) { memset(a,0,sizeof(a)); for(i=0;i { if(s[i]>='a'&&s[i] a
2013-02-04 15:20:02
240
原创 hdu 2399 GPA
HDU 2399 GPA http://acm.hdu.edu.cn/showproblem.php?pid=2399 #include #include int main() { char s[1000]; while(gets(s)) { double j=0.00; int sum=0,tag=1; for(int i=0;i { if(s[i]==' ')
2013-02-02 10:45:47
241
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅