2012年3月7日 星期三

分享

高中生程式解題系統 d498: 我不說髒話

#include <stdio.h>
#include <math.h>
#include <stdlib.h>


int main(void) 
{

    int n;

    scanf("%d",&n);

    int i;
    for(i=0;i<n;i++)
        printf("I don't say swear words!\n");

        
    return 0;
}
分享

高中生程式解題系統 d493: 入门求幂题(求幂系列题1)

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void) 
{

    long int a;
    long int n;
    double sum = 1;

    scanf("%d %d",&a,&n);

    if(n != 0)
    {
        sum = pow(a,n);
    }


    printf("%.f\n",sum);
        
    return 0;
}
分享

高中生程式解題系統 d491: 我也愛偶數 (swap 版)

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MAX( a, b )  (a > b) ? a : b
#define MIN( a, b )  (a < b) ? a : b



int main(void) 
{

    int a;
    int b;
    int big;
    int small;
    int sum = 0;

    scanf("%d %d",&a,&b);

    big = MAX(a,b);
    small = MIN(a,b);


    int i;
    for(i=small;i<=big;i++)
    {
        if(i % 2 == 0)
            sum += i;
    }


    printf("%d\n",sum);
    
    
    
    return 0;
}

2012年1月29日 星期日

分享

arg max

最近看論文總是會出現類似" y* = argmax f(t)"這種數學式子,還好網路上有人分享,請參考
http://kevingo75.blogspot.com/2009/04/arg-arg-max.html


y = f(t) 是一般常見的函式,代表給定一個t值,丟到f函式中會回傳一個值給y。

y = max f(t) 代表:y 是f(t)函式所有的值中最大的output。

y = arg max f(t) 代表:y 是f(t)函式中,會產生最大output的那個參數t。

舉例:

假設有一個函式 f(t),t 的可能範圍是 {0,1,2},f(t=0) = 10 ; f(t=1) = 20 ; f(t=2) = 7,那分別對應的y如下:

y = max f(t) = 20

y* = arg max f(t) = 1

相信大家都看懂了吧!