随笔分类 - 
        
            乱搞题
        
    
        
            
    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 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 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 2317 Nasty Hacks
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2317题意:判断做不做广告。胡搞题,看眼sample凑活一写就过了View Code #include <stdio.h>int main(){ int n,r,e,c,f; scanf("%d",&n); while(n--) { scanf("%d%d%d",&r,&e,&c); f=r-e+c; if(f<0)puts("advertise"); else if(f==0)puts("
         阅读全文
 
            
         
        
            
    HDU 4224 Enumeration?
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4224。。。对这题目无语了,本来是秒杀的题目就是让你读不懂。。。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ int x1,y1,x2,y2,x3,y3; int t,nCase=1; scanf("%d",&t); while(t--) { scanf("%d%d%d%d%d%d",&x1,&y1,&
         阅读全文
 
            
         
        
            
    HDU 4148 Length of S(n)
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4148找规律,后一项描述前一项每一段有多少连续的相同数字。ps:算到30项,总共的长度也不小了,开始s数组开小了,一直运行出错,郁闷好一会View Code #include <stdio.h>#include <string.h>#include <stdlib.h>char s[40][11000];int main(){ int n,i,j; int cnt,f; s[1][0]='1'; s[1][1]='\0'; for(i=2;i
         阅读全文
 
            
         
        
            
    HDU 1298 Hat’s IEEE
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1289对二进制数进行位运算。首先可以百度一下IEEE 754的规则。以6560.91为例:6560.91的二进制表示为1100110100000.111010001111010111,写成科学计数法就是1.100110100000111010001111010111 * 2^12s有一位,是符号位,为正数,符号位是0。e有八位,代表二进制数的指数,这时e就是12(sample输出的第一个数)。f代表有效部分,有23位,为100110100000111010001111010111 。所以,符号位是0然后用它的
         阅读全文
 
            
         
        
            
    HDU 3752 Is the one been second-killed first?
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3752捅死一只萌萌~View Code #include <stdio.h>int main(){ int t,m,n,i; scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); for(i=0;i<n-1;i++) m-=2; puts(m%2?"NO":"YES"); } return 0;}
         阅读全文
 
            
         
        
            
    HDU 1106 排序
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1106直接做不太方便,在网上新学一招。atoi这个函数原来做进制转换的时候就接触过。如果第一个非空格字符不存在或者不是数字也不是正负号则返回零,否则开始做类型转换,之后检测到非数字(包括结束符 \0) 字符时停止转换,返回整型数。(百度百科)简而言之是一个把字符型数字转化成整型的函数。strtok函数,感觉这个比较新鲜。下面从百度百科摘点介绍:原型 char *strtok(char *s, const char *delim);功能 分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。..
         阅读全文
 
            
         
        
            
    HDU 1013 Digital Roots
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1013按要求模拟View Code #include <stdio.h>#include <string.h>int main(){ int n; char a[1100]; while(gets(a)) { if(a[0]=='0')break; int len=strlen(a); n=0; for(int i=0;i<len;i++) { n+=a[i]-'0'; n...
         阅读全文
 
            
         
        
            
    HDU 2143 box
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2143除数为0re一次,用除法wa一次,加减互逆,乘除互逆,二者有一即可,这道题用除法会出问题。View Code #include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>__int64 a,b,c;int gao(){ if(a*b==c||a*c==b||b*c==a||a+b==c||a+c==b||b+c==a)return 1; if(a!=0) if(b%a==
         阅读全文
 
            
         
        
            
    HDU 3352 Tiles of Tetris, NOT!
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3352View Code #include <stdio.h>int gcd(int a,int b){ return a%b==0?b:gcd(b,a%b);}__int64 lcg(int a,int b){ return (__int64)a*(__int64)b/(__int64)gcd(a,b)/(__int64)gcd(a,b);} int main(){ int a,b; while(scanf("%d%d",&a,&b),(a||b)) prin
         阅读全文
 
            
         
        
            
    HDU 4218 IMBA?
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4218不用删最后的空格,fuckView Code #include <stdio.h>#include <math.h>int main(){ int t,r,a; int i,j; int nCase=1; scanf("%d",&t); while(t--) { scanf("%d",&r); a=2*r+1; printf("Case %d:\n",nCase++); for(i=0;i<a;i+
         阅读全文
 
            
         
        
            
    HDU 1205 吃糖果
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1205max为最大堆数量,s为总数。保证max-(s-max)=2*max-s<=1即可,因为只要能保证最大堆数量和其他堆数量差在一个以内,就可以做到别的堆拿一个最大堆拿一个(剩下yy)这种操作。View Code #include <stdio.h>int a[1100000];int main(){ int t,n; int i; __int64 s; int max; scanf("%d",&t); while(t--) { s=max=0; ...
         阅读全文
 
            
         
        
            
    HDU 1248 寒冰王座
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1248我乱搞的,标准做法01背包View Code #include <stdio.h>int test(int n){ if(n<150)return n; if(n>200&&n<300)return n-200; return n%50;}int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n
         阅读全文
 
            
         
        
            
    HDU 2116 Has the sum exceeded
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2116判断两个k位带符号数的和有木有溢出。判断的时候注意不能用两个数的和判断,否则溢出的话会有bug。这里的方法是用最值减其中一个数,再和另一个数比较。View Code #include <stdio.h>int k;__int64 a,b;__int64 pow(int x,int y){ int i; __int64 s=1; for(i=0;i<y;i++) s*=x; return s;}#define MAX pow(2,63) int test(){ ...
         阅读全文
 
            
         
        
            
    HDU 2552 三足鼎立
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2552数学推导View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int t; scanf("%d",&t); while(t--) { scanf("%*lf%*lf"); printf("1\n"); } return 0;}
         阅读全文
 
            
         
        
            
    HDU 2523 SORT AGAIN
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2523求差的绝对值第k大的数,注意相同的差算一个。分析出差的绝对值在[0,2000]这个范围内,由此可以搞出hash数组View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int abs(int a){ return a>0?a:-a;}int a[3000],hash[5000];int main(){ int t,n,k; int i,j; scanf("%d",&
         阅读全文
 
            
         
        
            
    HDU 2190 悼念512汶川大地震遇难同胞——重建希望小学
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2190考虑两种砖,得出递推公式。a[i]=a[i-1]+2*a[i-2]View Code #include <stdio.h>int main(){ int n,i; __int64 a[40]={0,1,3}; for(i=3;i<=30;i++) a[i]=a[i-1]+2*a[i-2]; scanf("%d",&n); while(n--) { scanf("%d",&i); printf("%I64d\n"
         阅读全文
 
            
         
    
 
    
 
 | 
                 
             
         |