<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQYBI.com &#187; UVa</title>
	<atom:link href="http://sqybi.com/blog/archives/tag/uva/feed" rel="self" type="application/rss+xml" />
	<link>http://sqybi.com/blog</link>
	<description>Change is a part of life, and takes part in finding us who we are.</description>
	<lastBuildDate>Mon, 09 Jan 2012 13:33:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>UVa 102 -- Ecological Bin Packing</title>
		<link>http://sqybi.com/blog/archives/23</link>
		<comments>http://sqybi.com/blog/archives/23#comments</comments>
		<pubDate>Fri, 22 Aug 2008 09:10:49 +0000</pubDate>
		<dc:creator>sqybi</dc:creator>
				<category><![CDATA[About Computer]]></category>
		<category><![CDATA[[OI, ACM, etc]]]></category>
		<category><![CDATA[UVa]]></category>
		<category><![CDATA[枚举]]></category>

		<guid isPermaLink="false">http://sqybi.com/blog/archives/23</guid>
		<description><![CDATA[水题,枚举即可. 第一次提交WA,没有注意这道题并不是Special Judge,如果有多组顺序符合要求,需要输出字典序最靠前的一组. 虽然用了string,不过代码写的还是很垃圾. /* UVa 102; Ecological Bin Packing - sqybi's code */ //for my winsty #include #include using namespace std; const int nn = 3; int t, res, now; int a[nn][nn]; bool u[nn]; char ch[nn] = {'B', 'G', &#8230; <a href="http://sqybi.com/blog/archives/23">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>水题,枚举即可.<br />
第一次提交WA,没有注意这道题并不是Special Judge,如果有多组顺序符合要求,需要输出字典序最靠前的一组.<br />
虽然用了string,不过代码写的还是很垃圾.</p>
<pre lang="cpp">/*
  UVa 102; Ecological Bin Packing
  - sqybi's code
*/
//for my winsty

#include
#include
using namespace std;

const int nn = 3;
int t, res, now;
int a[nn][nn];
bool u[nn];
char ch[nn] = {'B', 'G', 'C'};
string ress, nows;

void get(int i)
{
    if (i == 3)
    {
        if (now &gt; res || (now == res &amp;&amp; nows &lt; ress))
        {
            res = now;
            ress = nows;
        }
        return;
    }
    for (int j = 0; j != 3; ++ j)
        if (! u[j])
        {
            u[j] = true;
            now = now + a[i][j];
            nows += ch[j];
            get(i+1);
            nows = nows.erase(i, 1);
            now = now - a[i][j];
            u[j] = false;
        }
}

int main()
{
    while (scanf("%d", &amp;a[0][0]) != EOF)
    {
        t = a[0][0];
        for (int i = 0; i != 3; ++ i)
            for (int j = 0; j != 3; ++ j)
                if (i + j)
                {
                    scanf("%d", &amp;a[i][j]);
                    t += a[i][j];
                }
        res = 0;
        now = 0;
        nows = "";
        memset(u, false, sizeof(u));
        get(0);
        cout &lt;&lt; ress &lt;&lt; ' ' &lt;&lt; t - res &lt;&lt; endl;
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://sqybi.com/blog/archives/23/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UVa 100 -- The 3n + 1 problem</title>
		<link>http://sqybi.com/blog/archives/22</link>
		<comments>http://sqybi.com/blog/archives/22#comments</comments>
		<pubDate>Thu, 21 Aug 2008 16:09:12 +0000</pubDate>
		<dc:creator>sqybi</dc:creator>
				<category><![CDATA[About Computer]]></category>
		<category><![CDATA[[OI, ACM, etc]]]></category>
		<category><![CDATA[UVa]]></category>
		<category><![CDATA[搜索]]></category>

		<guid isPermaLink="false">http://sqybi.com/blog/archives/22</guid>
		<description><![CDATA[经典的3n+1,没有想到这道题调了一个晚上. 在Project Euler上看过这道题,于是按照那道题写了个部分DP.然后诡异的WA了. 调啊,调啊,只找到了一个trick:输入的两个数不一定小数在前大数在后. 然后呢,我这个程序是search,可加了一个预处理,for i=1~10000 do dp[i]=f(i),然后调用f(i)的地方改成dp[i],就过不了,都鬼了...怀疑数据范围有问题. search可以1s过掉. /* UVa 100; The 3n + 1 problem - sqybi's code */ //for my winsty //#define DEBUG #include using namespace std; const int nn = 1000001, mm = 10001; int l, &#8230; <a href="http://sqybi.com/blog/archives/22">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>经典的3n+1,没有想到这道题调了一个晚上.<br />
在<a href="http://projecteuler.net" target="_blank">Project Euler</a>上看过这道题,于是按照那道题写了个部分DP.然后诡异的WA了.<br />
调啊,调啊,只找到了一个trick:输入的两个数不一定小数在前大数在后.<br />
然后呢,我这个程序是search,可加了一个预处理,for i=1~10000 do dp[i]=f(i),然后调用f(i)的地方改成dp[i],就过不了,都鬼了...怀疑数据范围有问题.</p>
<p>search可以1s过掉.</p>
<pre lang="cpp">/*
  UVa 100; The 3n + 1 problem
  - sqybi's code
*/
//for my winsty

//#define DEBUG
#include
using namespace std;

const int nn = 1000001, mm = 10001;
int l, r, ll, rr, maxa;

int f(int i)
{
    if (i == 1)
        return 1;
    else if (i % 2)
        return f(i*3+1)+1;
    else
        return f(i/2)+1;
}

int main()
{
    #ifdef DEBUG
    freopen("uva100.in", "r", stdin);
    freopen("uva100.out", "w", stdout);
    #endif

    while (scanf("%d%d", &amp;ll, &amp;rr) != EOF)
    {
        l = ll;
        r = rr;
        if (l &gt; r) swap(l, r);
        maxa = 0;
        for (int i = l; i &lt;= r; ++ i)
            if (f(i) &gt; maxa) maxa = f(i);
        printf("%d %d %d\n", ll, rr, maxa);
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://sqybi.com/blog/archives/22/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

