随笔分类 -
HDU
HDU 4217 Data Structure?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4217经典的线段树问题,找第k小数。注意sum用__int64View Code #include <stdio.h>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=300000;int tree[maxn<<2];int temp;void build(int l,int r,int rt){ tree[rt]=r-l+1; if(l==r) return; int m=(l+r)&
阅读全文
HDU 2140 Michael Scofield's letter
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2140按题意翻译字符串View Code #include <stdio.h>#include <string.h>int main(){ char tab[10][2]={{'b',' '},{'q',','},{'t','!'},{'m','l'},{'i','e'},{'c','a'},{&
阅读全文
HDU 1212 Big Number
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1212大整数取模问题(a+b) mod n=((a mod n)+(b mod n)) mod nView Code #include <stdio.h>#include <string.h>int main(){ char s[1100]; int n; int len,ans,i; while(~scanf("%s%d",s,&n)) { len=strlen(s); ans=0; for(i=0;i<len;i++) ...
阅读全文
HDU 2710 Max Factor
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2710找出拥有最大素因子的数,基本的素数筛选View Code #include <stdio.h>int prime[110000];int main(){ int t,n; int i,j; int max,maxnum; for(i=2;i*i<=100001;i++) if(!prime[i]) for(j=i;j*i<=100001;j++) prime[i*j]=1; while(~scanf("%d"...
阅读全文
HDU 1339 A Simple Task
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1339n=o*2^p,已知n,求o和p水、、、View Code #include <stdio.h>#include <string.h>int main(){ int t,n; int cnt; scanf("%d",&t); while(t--) { scanf("%d",&n); if(n%2) printf("%d 0\n",n); else { cnt=0; ...
阅读全文
HDU 1391 Number Steps
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1391水View Code #include <stdio.h>#include <string.h>int main(){ int t; int x,y; scanf("%d",&t); while(t--) { scanf("%d%d",&x,&y); if(x!=y&&x!=y+2) puts("No Number"); else { if(y%2) ...
阅读全文
HDU 1496 Equations
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1496今天刚知道这种方法叫哈希。。。开始没考虑清楚边界,各种错,A了再看也就那么回事View Code #include <stdio.h>#include <string.h>const int N=1000000;int hash[2000001];int main(){ int a,b,c,d; int ans; int i,j; while(~scanf("%d%d%d%d",&a,&b,&c,&d)) { if((a>
阅读全文
HDU 1491 Octorber 21st
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1491无聊题View Code #include <stdio.h>int main(){ int t,i; int month,day,now; int tab[11]={0,31,28,31,30,31,30,31,31,30}; scanf("%d",&t); while(t--) { scanf("%d%d",&month,&day); if(month>10||(month==10&&day>21
阅读全文
HDU 1176 免费馅饼
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1176类似数塔的dp,注意边界处理!!!View Code #include <stdio.h>#include <string.h>int dp[110000][30];int max3(int a,int b,int c){ int maxnum=a; if(maxnum<b)maxnum=b; if(maxnum<c)maxnum=c; return maxnum;}int max2(int a,int b){ return a>b?a:b;}int main(
阅读全文
HDU 1492 The number of divisors(约数) about Humble Numbers
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1492计算约数的个数,由已知条件"A number whose only prime factors are 2,3,5 or 7 is called a humble number."简化运算。View Code #include <stdio.h>__int64 find(__int64 n,int a){ __int64 ans=0; while(1) { if(n==1)break; if(n%a==0) { ans++...
阅读全文
HDU 1593 find a way to escape
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1593吐槽:大晚上的说好复习高数又有点变味儿了、、、囧这道题问的是怎么能够逃脱。开始写的直接往相反方向跑,wa了,查别人的解题报告说找同心圆使两人角速度相等,然后再往反方向跑。代码很简单,但不太容易想。ps:角速度w=v/rView Code #include <stdio.h>#define PI 3.1415926535int main(){ double r,v1,v2; while(~scanf("%lf%lf%lf",&r,&v1,&v2))
阅读全文
HDU 1087 Super Jumping! Jumping! Jumping!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1087求最长上升子序列问题View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int cmp(const void*a,const void*b){ return *(int*)b-*(int*)a;}int main(){ int n,i,j; int a[1100],dp[1100]; while(scanf("%d",&n),n) { for(i=0;i<
阅读全文
HDU 2103 Family planning
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2103bs这道题,我坚信生男生女都一样!ps:不提前把几个0打出来的话要用__int64,否则会超范围View Code #include <stdio.h>int main(){ int t,m,n; int i; int bb,cnt,f; __int64 ans,fj; scanf("%d",&t); while(t--) { cnt=ans=f=0; fj=10000; scanf("%d%d",&m,&n); ...
阅读全文
HDU 1222 Wolf and Rabbit
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1222题意:判断兔纸酱能否存活求最大公约数。分析:如狼能从0到1,则狼能到任意洞。要使狼能到1,则gcd(m,n)=1View Code #include <stdio.h>int gcd(int a,int b){ return a%b==0?b:gcd(b,a%b);}int main(){ int p,m,n; scanf("%d",&p); while(p--) { scanf("%d%d",&m,&n); if(gcd(m,
阅读全文
HDU 4104 Discount
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4104第一遍看了眼数据,直接输出所有数的和加1,居然过了,不过我相信一切都是有原因的~View Code #include <stdio.h>int main(){ int n,s,a,i; while(~scanf("%d",&n)) { s=0; for(i=0;i<n;i++) { scanf("%d",&a); s+=a; } printf("%d\n",s+1); ...
阅读全文
HDU 2719 The Seven Percent Solution
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2719按要求处理字符串View Code #include <stdio.h>#include <string.h>int main(){ char s[1100]; char tab1[30]={' ','!','$','%','(',')','*'}; char tab2[10][20]={{"%20"},{"%21"},{&quo
阅读全文
HDU 2743 Quicksum
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2734按规则计算就行,很简单、、、View Code #include <stdio.h>#include <string.h>int main(){ char s[1100]; char tab[30]={' ','A','B','C','D','E','F','G','H','I','J','K
阅读全文
HDU 2700 Parity
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2700读懂了发现就是一个奇偶判断View Code #include <stdio.h>#include <string.h>int main(){ char s[1100]; int len,cnt,i; while(gets(s)) { cnt=0; if(s[0]=='#')break; len=strlen(s); for(i=0;i<len-1;i++) if(s[i]=='1')cnt++; ...
阅读全文
HDU 2740 Root of the Problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2740题意:找到A,另A^N最接近B思路:逆向考虑,B^(1/n)上下取整,在各取N次幂,看哪个更接近Bps:注意上下取整View Code #include <stdio.h>#include <math.h>int main(){ int b,n; double temp; int p,q; while(scanf("%d%d",&b,&n),(b||n)) { temp=pow(b*1.0,1.0/n); p=floor(temp);//向下取
阅读全文
HDU 1789 Doing Homework again
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1789贪心,按价值从大到小排序,然后尽可能的安排到截止时间View Code #include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct L{ int a,b;}L;L kk[1100];int cmp(const void*a,const void*b){ L*c=(L*)a; L*d=(L*)b; if(c->b==d->b) return c->a-d->a; r
阅读全文
|
|