CDOJ 1273 God Qing's circuital law

暴力枚举+idea。做的时候mod写错了,写成了1000000009,找了两个多小时才发现......

a[1],a[2],a[3]....a[N]

b[1],b[2],b[3]....b[N]

首先需要枚举b[1]...b[N]与a[1]进行组合。

然后对a[2]...a[N]从小到大排序

对b[1],b[2],b[3]....b[N] 除当前与a[1]组合的以外,剩下的从大到小排序

然后找出每一个a[i]在不破坏a[0]最大值的情况下最大能与哪一个b[i]配对。

然后从第N个人开始往第2个人开始计算,先算N有几种取法,然后算N-1有几种。。。一直算到第2个人有几种

然后把这些数字乘起来就是当前这一次枚举的答案,最后把所有答案加起来就是了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

const int maxn = 100 + 10;
const long long MOD = 1000000007;
long long tmpa[maxn];
long long tmpb[maxn];
long long a[maxn];
long long b[maxn];
long long flag[maxn];
int n;

bool cmp(const long long&a, const long long&b)
{
    return a>b;
}

int main()
{
    while (~scanf("%d", &n))
    {
        for (int i = 1; i <= n; i++) scanf("%lld", &tmpa[i]);
        for (int i = 1; i <= n; i++) scanf("%lld", &tmpb[i]);

        long long ans = 0;
        for (int t = 1; t <= n; t++)
        {
            long long top = tmpa[1] * tmpb[t];

            for (int i = 1; i <= n - 1; i++) a[i] = tmpa[i + 1];

            int u = 1;
            for (int i = 1; i <= n; i++)
            {
                if (i == t) continue;
                else b[u++] = tmpb[i];
            }

            int tot = n - 1;
            sort(a + 1, a + 1 + tot);
            sort(b + 1, b + 1 + tot, cmp);

            for (int i = 1; i <= n; i++) flag[i] = (long long)1000;
            for (int i = 1; i <= tot; i++)
            {
                for (int j = 1; j <= tot; j++)
                {
                    if (a[i] * b[j] >= top){}
                    else
                    {
                        flag[i] = (long long)j;
                        break;
                    }
                }
            }

            long long ans_tmp = 1;
            bool fail = 0;
            for (int i = 1; i <= tot; i++)
            if (flag[i] > (long long)i) { ans_tmp = 0; fail = 1; break; }

            if (fail == 0)
            {
                long long now = 0;
                long long newpos = (long long)(tot + 1);
                for (int i = tot; i >= 1; i--)
                {
                    long long newz = 0;
                    if (flag[i] < newpos)
                    {
                        newz = newpos-flag[i];
                        newpos = flag[i];
                    }
                    now = now + newz;
                    ans_tmp = (ans_tmp*now) % MOD;
                    now--;
                }
            }
            ans = (ans + ans_tmp) % MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

CDOJ 1273 God Qing's circuital law

时间: 2024-10-25 13:40:51

CDOJ 1273 God Qing's circuital law的相关文章

ural 1273. Tie

1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and t

默菲定律 [Murphy&#39;s Law]

一.关于默菲定律(Murphy's Law)   “墨菲定律”.“帕金森定律”和“彼德原理”并称为二十世纪西方文化三大发现. “墨菲定律”的原话是这样说的:If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.(如果有两种或两种以上的方式去做某件事情,而其中一种选择方式将导致灾难,则必定有人会作出这种选择.)

POJ 1273 Drainage Ditches(网络流 最大流)

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 55893   Accepted: 21449 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by

帕金森定律(Parkinson&#39;s Law)

帕金森定律(Parkinson's Law)是官僚主义或官僚主义现象的一种别称, 是由英国历史学家.政治学家西里尔·诺斯古德·帕金森(Cyril Northcote Parkinson)通过长期调查研究并于1958年出版了<帕金森定律>(Parkinson's Law)一书,其主要内容可分为9个方面来禅述: 1.冗员增加原理:官员数量增加与工作量并无关系,而是由两个源动因造成的.每一个官员都希望增加部属而不是对手(如“投票”):官员们彼此为对方制造工作(如行政审批,工商.税务.审计.公安,既得

Zipf&#39;s law

w https://www.bing.com/knows/search?q=马太效应&mkt=zh-cn&FORM=BKACAI 马太效应(Matthew Effect),指强者愈强.弱者愈弱的现象,广泛应用于社会心理学.教育.金融以及科学领域.马太效应,是社会学家和经济学家们常用的术语,反映的社会现象是两极分化,富的更富,穷的更穷.名字来自圣经<新约·马太福音>一则寓言:"凡有的,还要加倍给他叫他多余:没有的,连他所有的也要夺过来"."马太效应&

CDOJ 26 遮挡判断(shadow) 解题报告

题目链接http://acm.uestc.edu.cn/#/problem/show/26 出题目的给我说清东边是哪一边啊魂淡! 分析样例可得,东边是先读入数据的那一边. 这题主要考察排序,然而感谢上苍我有<algorithm> 另外,CDOJ是可以用C++11标准的匿名函数的,所以sort的比较函数我就打了匿名的 这题只要记录一下扫到的柱子中投影最西边最靠西的那根,不妨设为柱子h 如果这根柱子h能完全遮住当前扫到的柱子i,那么柱子h仍然是影子最靠西的柱子 如果这根柱子h不能完全遮住当前扫到的

Erd\H{o}s-R\&#39;enyi Law

Let $0<p=1-q<1$ and $X_1,X_2,\ldots$ be an i.i.d. Bernoulli sequence with $p=\mathbb{P}(X_i=1)=1-\mathbb{P}(X_i=0)$. Denote by $S_n$ the length of the longest consectutive run of heads (i.e., $1$'s) within the first $n$ tosses. Erd\H{o}s-R\'enyi Law

Zipf’s Law

Let f(w) be the frequency of a word w in free text. Suppose that all the words of a text are ranked according to their frequency, with the most frequent word first. Zipf’s Law states that the frequency of a word type is inversely proportional to its

里特定律 - Little&#39;s Law

里特定律(Little's Law)源自排队理论,是IT系统性能建模中最广为人知的定律. 里特定律揭示了前置时间(Lead Time).在制品数量(Work In Progress, WIP)和吞吐率(Throughput)之间的关系. 前置时间 - Lead time:只请求进入到系统 与 请求验收完成之间的时间段.前置时间按照所经过的时间(分钟.小时等)来度量.一个请求可以是一个需求.一个用户故事.一个异常.物料.一个来自用户的请求等. 在制品数量 - Work in progress (W