Crossings

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100463

Description

Given a permutation P of {0, 1, ..., n − 1}, we define the crossing number of it as follows. Write the sequence 0, 1, 2, . . . , n − 1 from left to right above the sequence P(0), P(1), . . . , P(n − 1). Draw a straignt line from 0 in the top line to 0 in the bottom line, from 1 to 1, and so on. The crossing number of P is the number of pairs of lines that cross. For example, if n = 5 and P = [1, 3, 0, 2, 4], then the crossing number of P is 3, as shown in the figure below. !""""#""""""""""""&" In this problem a permutation will be specified by a tuple (n, a, b), where n is a prime and a and b are integers (1 ≤ a ≤ n − 1 and 0 ≤ b ≤ n − 1). We call this permutation Perm(n, a, b), and the ith element of it is a ∗ i + b mod n (with i in the range [0, n − 1]). So the example above is specified by Perm(5, 2, 1).

Input

There are several test cases in the input file. Each test case is specified by three space-separated numbers n, a, and b on a line. The prime n will be at most 1,000,000. The input is terminated with a line containing three zeros.

Output

For each case in the input print out the case number followed by the crossing number of the permutation. Follow the format in the example output.

Sample Input

5 2 1

19 12 7

0 0 0

Sample Output

Case 1: 3

Case 2: 77

给你三个数n,a,b

满足第i个数等于(a*i+b)%n,然后问你逆序数是多少

这个n有1e6呢,所以树状数组和归并都能解决这个题吧

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+;
int d[N];
ll n,a,b;
void update(int x,int y) {
while(x<=n) {
d[x]+=y;
x+=x&-x;
}
}
int sum(int x) {
int s=;
while(x>) {
s+=d[x];
x-=x&-x;
}
return s;
}
int main() {
int k=;
while(~scanf("%lld%lld%lld",&n,&a,&b)) {
if(!n&&!a&&!b)
break;
memset(d,,sizeof(d));
ll ans=;
for(int i=; i<n; i++) {
int x=(a*i+b)%n+;
ans+=sum(x-);
update(x,);
}
printf("Case %d: %lld\n",k++,(n-)*n/-ans);
}
}

2011 Michigan Invitational Programming Contest的更多相关文章

  1. The North American Invitational Programming Contest 2017 题目

    NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K   A mysterious circular arrangement of black st ...

  2. 2014 ACM-ICPC Beijing Invitational Programming Contest

    点击打开链接 Happy Reversal Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      J ...

  3. The North American Invitational Programming Contest 2018 D. Missing Gnomes

    A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...

  4. The North American Invitational Programming Contest 2018 H. Recovery

    Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...

  5. The North American Invitational Programming Contest 2018 E. Prefix Free Code

    Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...

  6. North American Invitational Programming Contest (NAIPC) 2017

    (待补) A. Pieces of Parentheses 将括号处理完成后排序,方式参加下面的博客.然后做一遍背包即可. 2018 Multi-University Training Contest ...

  7. North American Invitational Programming Contest (NAIPC) 2016

    (待补) A. Fancy Antiques 爆搜. B. Alternative Bracket Notation C. Greetings! D. Programming Team 0/1分数规划 ...

  8. North American Invitational Programming Contest 2018

    A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...

  9. BNU 34990 Justice String 2014 ACM-ICPC Beijing Invitational Programming Contest

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34990 DEBUG了非常久,还是legal的推断函数写错了... 此题做法.枚举Stri ...

随机推荐

  1. 前端之css(宽高)设置小技巧

    一.css宽高自适应: 1.宽度自适应: 元素宽度设为100%(块状元素的默认宽度为100%) 注:应用在通栏效果中 2.高度自适应: height:auto;或者不设置高度 3.最小,最大高度,最小 ...

  2. Spring AOP初步总结(一)

    学习AOP有段时间了,一直没空总结一下,导致有些知识点都遗忘了,之后会把以前学过的Spring核心相关的知识点总结一轮... 先大体介绍下Spring AOP的特点(均摘自"Spring i ...

  3. CF1066B Heaters

    思路: 从左向右贪心选择能覆盖当前位置的最靠右的那个heater即可,和poj radar installation类似. 实现: #include <iostream> #include ...

  4. SVN上传文件过程中出现错误“不知道这样的主机”

    在虚拟机中安装完成VisualSVN Server,并且在本地客户端也安装好了TortoiseSVN,在上传文件到服务器的过程中出现错误“不知道这样的主机”,如下图: 地址https://admin- ...

  5. Windows 10下mysql 64位 安装(mysql-5.7.11-winx64安装)

    Windows下mysql 64位 安装(mysql-5.7.11-winx64安装) 系统Windows10 安装包mysql-5.7.11-winx64.zip 安装过程中遇到的问题,请留意4.0 ...

  6. 【读书笔记】构建之法(CH1~CH3)

    人类文明的发展离不开哲学家的思考.科学家的发现和工程师的构建.三个简单的方程式解释了什么是现代软件工程: 1.程序=算法+数据结构 2.软件=程序+软件工程 3.软件企业=软件+商业模式 软件开发的不 ...

  7. jmeter并发定时器

    jmeter并发定时器

  8. 洛谷 P2292 [HNOI2004]L语言

    题目描述 标点符号的出现晚于文字的出现,所以以前的语言都是没有标点的.现在你要处理的就是一段没有标点的文章. 一段文章T是由若干小写字母构成.一个单词W也是由若干小写字母构成.一个字典D是若干个单词的 ...

  9. Python学习日志9月13日

    昨天的学习日志没有写,乱忙了一整天,政治电脑. 好奇心重,想要给电脑装上传说中LInux操作系统,各种小问题折腾到半夜,今天又折腾到晚上才真正的装上系统. 可是装上系统后又发现各种的不好用.虽然界面比 ...

  10. postcss.config.js配置文件的配置方法

    module.exports = { plugins: { 'autoprefixer': {}, } }