暑期集训 DAY3

来源:互联网 发布:淘宝评价采集器 编辑:程序博客网 时间:2024/05/01 11:49

一、纸牌游戏,判断胜负
难点在于有可能碰到无限循环的对局
题在这里http://codeforces.com/contest/546/problem/C
可以计算得到整个游戏中所有可能的状态(state)数:(n+1)!
即:先将n张牌放到n个位置有n!种可能,再分给两个人,有(n+1)种划分方法(包括一方没分到的情况)
所以如果循环次数大于(n+1)!表示某种状态出现了两次,这时break掉即可
大神说:
通过计算可以知道state-graph最长是106,即循环次数大于106就可以判定为平局了……
猜测大佬是用dfs计算的最长路径,代码,,回头试试吧
题解:

//#304 div2   c#include<iostream>#include<queue>using namespace std;int main(){int m;while(cin>>m){    int n1,n2;    queue<int> q1,q2;    cin>>n1;    for(int i=0 ; i<n1; i++)    {        int temp;        cin>>temp;        q1.push(temp);    }    cin>>n2;    for(int i=0;i<n2;i++)    {        int temp;        cin>>temp;        q2.push(temp);    }    int rundcont=0,flag=0;    while(!q1.empty() && !q2.empty())    {        if(rundcont>110)                   // <-----here        {            cout<<-1<<endl;            flag=1;            break;        }        int card1=q1.front(),card2=q2.front();        q1.pop();q2.pop();        if(card1>card2)        {            q1.push(card2);            q1.push(card1);        }        else        {            q2.push(card1);            q2.push(card2);        }        rundcont++;    }    if(flag)        continue;    int win;    if(q1.empty())        win=2;    else        win=1;    cout<<rundcont<<" "<<win<<endl;}return 0;}

二、可能报RE的点
为具体的值开数组时(array[number],number 是程序中用到的数值)
下意识开到数据的最大数量结果一直RE
http://codeforces.com/contest/546/problem/B

//#304 div2  b #include<algorithm>#include<iostream>#include<cstring>using namespace std;int exis[10050];                  //<---hereint main(){int n;while(cin>>n){    memset(exis,0,sizeof(exis));    int num[3050],sum=0;    for(int i=0;i<n;i++)        cin>>num[i];    sort(num,num+n);    for(int i=0;i<n;i++)    {        while(exis[num[i]])        {            num[i]++;            sum++;        }        exis[num[i]]=1;    }    cout<<sum<<endl;}return 0;

}


三、从上一个中发现的—手动扩栈

/*    C++    */#pragma comment(linker, "/STACK:102400000,102400000")/*    G++   */int size = 256 << 20; // 256MBchar *p = (char*)malloc(size) + size;__asm__("movl %0, %%esp\n" :: "r"(p));

百度 pragma comment 后得到:
#pragma comment( comment-type ,[“commentstring”] )
comment-type是一个预定义的标识符,指定注释的类型,应该是compiler,exestr,lib,linker之一。
commentstring是一个提供为comment-type提供附加信息的字符串。
指定一个连接选项,这样就不用在命令行输入或者在开发环境中设置了。
只有下面的linker选项能被传给Linker.
/DEFAULTLIB ,/EXPORT,/INCLUDE,/MANIFESTDEPENDENCY, /MERGE,/SECTION

又在微软的文档(https://msdn.microsoft.com/zh-cn/library/8cxs58a6.aspx)里找到了链接器选项列表其中有:

/STACK 选项设置堆栈的大小(以字节为单位)。 此选项仅在生成 .exe 文件时使用。
reserve 值指定虚拟内存中的总的堆栈分配。 对于 ARM、x86 和 x64 计算机,默认堆栈大小为 1 MB。
commit 取决于操作系统所作的解释。 在 Windows WindowsRT 中,它指定一次分配的物理内存的数量。 提交的虚拟内存导致空间被保留在页面文件中。 更高的 commit 值在应用程序需要更多堆空间时可节省时间,但会增加内存需求并有可能延长启动时间。 对于 ARM 、x86 和 x64 计算机,默认提交值为 4 KB。
以十进制或 C 语言表示法指定 reserve和 commit 值。
设置堆栈大小的另一种方法是使用模块定义 (.def) 文件中的 STACKSIZE 语句。 如果两者都指定,则 STACKSIZE 重写堆栈分配 (/STACK) 选项。 可以使用 EDITBIN 工具在生成 .exe 文件之后更改堆栈大小。


四、最后是大神的比赛策略

  1. Read all the problems. Usually starting with the last one, but it’s
    not important.
  2. While reading each problem, try to understand what it asks for,
    think about it for a minute.
  3. Start thinking about problems in random order, frequently jumping
    from one problem to another.
  4. Strive to make progress or look at a problem from a different
    perspective every time you get back to it. For easy problems, this
    usually means solving them from the first try, as there’s little
    progress to be made.
  5. Look at the scoreboard to get a grasp of the amount of time people
    typically spend on each problem. This helps understand whether one
    should look for a simple solution.
  6. At some moment, I feel stuck in every problem I haven’t solved yet
    (possibly an empty set). This usually happens during the first half
    of the contest. Implement solutions to solved problems in any
    comfortable order. Submit them. Here, there are two main options:
    submit a solution after implementing it, or do a batch submit after
    implementing all of them. I’ve tried both, and I think it doesn’t
    matter too much. At least the latter option doesn’t make me upset
    with WA in the process of implementing another solution, and also
    saves me from the urge of refreshing the submissions page for each
    problem separately :)
  7. Try to solve the rest of the problems, again jumping between
    problems if there’s more than one, but spending more time on one
    problem in a row. Once a problem is solved, implement its solution
    and submit.

http://codeforces.com/blog/entry/53457

原创粉丝点击