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+10;
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=0;while(x>0) {s+=d[x];x-=x&-x;}return s;
}
int main() {int k=1;while(~scanf("%lld%lld%lld",&n,&a,&b)) {if(!n&&!a&&!b)break;memset(d,0,sizeof(d));ll ans=0;for(int i=0; i<n; i++) {int x=(a*i+b)%n+1;ans+=sum(x-1);update(x,1);}printf("Case %d: %lld\n",k++,(n-1)*n/2-ans);}
}

转载于:https://www.cnblogs.com/BobHuang/p/7258369.html

2011 Michigan Invitational Programming Contest相关推荐

  1. 2011 Heilongjiang collegiate programming contest 【(7+1)/10】 [补完]

    题目链接: [CDOJ] https://vjudge.net/contest/170394#overview [hrbust1395~1402(中文题面哦!) ] http://acm.hrbust ...

  2. The North American Invitational Programming Contest 2016 - Tourists ( LCA )

    题意 给出一棵n个点,n-1条边的树.现在计算所有标号为x到y的距离之和(满足y>x且y是x的倍数) 思路 关于树上任意两点距离之和,一开始想到树形dp,可树形dp,是对每条边,求所有可能的路径 ...

  3. 2015 HIAST Collegiate Programming Contest J

    Polygons Intersection 题意:给2个凸多边形,求相交面积 思路:不会,套板子就是了 AC代码: #include "iostream" #include &qu ...

  4. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  5. The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554

    地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others)     M ...

  6. 【AtCoder】diverta 2019 Programming Contest 2

    diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...

  7. 2018 German Collegiate Programming Contest (GCPC 18)

    2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...

  8. Atcoder Keyence Programming Contest 2020 D - Swap and Flip

    Atcoder Keyence Programming Contest 2020 D - Swap and Flip 题目描述 Solution 写了一个简单的O(2nn(n+w))O(2^nn(n+ ...

  9. 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)

    2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018) 题号 题目 知识点 难度 A Access ...

最新文章

  1. hive 常见面试题
  2. 雅客EXCEL(1)--快速录入、统计、日期
  3. overflowhidden把内容遮住了怎么办_图片有水印怎么办?不用PS,有这4招就够了!...
  4. linux rsa登录改密码登录_LINUX中RSA认证登录SSH(不需要输入密码登录)2种方法
  5. mysql5.5和5.6版本间的坑
  6. 小数乘分数怎么算过程_教资分数怎么算?多少分合格?
  7. java多线程 同一资源_同一资源多线程并发访问时的完整性
  8. tomcat下面的starup.bat的作用
  9. 算法笔记(个人用)(不定期更新)
  10. 分享个手游剑侠情缘2挂机脚本,能够多开刷银两的工具
  11. MTT预实验与免疫染色准备
  12. 京东商城搜索框特效实现
  13. 小米air2se耳机只有一边有声音怎么办_不到200元 小米蓝牙耳机Air2 SE是真香党的选择吗?...
  14. Qt实现Linux下的硬盘空间监测和文件清理
  15. 3dmax基础知识:3dmax常用功能详解,零基础小白的福音
  16. 解决Pycharm装Illuminated Cloud之后无法创建项目的思路_艾孜尔江撰稿
  17. WIN8.1下Prolific USB-to-Serial Comm Port驱动黄色感叹号问题
  18. Vue的@click、@click.prevent、@click.stop
  19. 关于一些不为人知的小秘密
  20. 环信php修改头像,环信第二波 更改聊天头像,昵称等问题

热门文章

  1. 【AllJoyn专题】基于AllJoyn和Yeelink的传感器数据上传与指令下行的研究
  2. oracle中生成大批量数据的方法-下
  3. 一道终身受用的测试题
  4. TechED 2005 博客园兄弟合影
  5. centos7重新加载服务的命令_阿粉手把手教你在 CentOS7 下搭建 Jenkins
  6. RID枚举工具RidEnum
  7. 分享Kali Linux 2016.2第45周镜像
  8. Xamarin iOS教程之显示和编辑文本
  9. Xamarin iOS开发实战1.1.3Xamarin版本
  10. java输出五行菱形_Java打印一个菱形