Infernal Work

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Railwaymen Vassily and Pyotr died and were sent to Hell. Their first punishment was to perform a complete inspection of the Moscow–Vladivostok railroad. They spent many weeks walking along the railroad together, one of them along the left rail and the other along the right rail, writing the long serial numbers of ties to their thick notebooks. As soon as they finished that infernal task, they immediately got a new task, which was even more meaningless. Now they had to count the number of pairs of ties that were written in Vassily's notebook on the same page and in Pyotr's notebook on different pages.
The friends came to you in a dream and asked you to save them from that terrible torment.

Input

The only input line contains integers abn (1 ≤ ab ≤ n ≤ 25 000 000). One page in Vassily's notebook comprises a numbers of ties, and one page in Pyotr's notebook comprises b numbers of ties. They have written numbers of n ties. All these numbers are different and are written in their notebooks in the same order.

Output

Output one number, which is the answer to the problem.

Sample Input

input output
3 4 10
4
2 4 10
0

Notes

Let the ties in the first sample be numbered by the letters from A to J. Then the following four pairs satisfy the condition: (D, E), (D, F), (G, I), (H, I).
 
 
首先看第一种方法(超出空间限制):
 #include <iostream>
using namespace std; struct Data{
long long zua;
long long zub;
};
//本题的思路是为两种不同的分组方式分别赋予不同的组别值,
//然后搜索符合题目要求的配对。
int main(){
long long a,b,n;
cin>>a>>b>>n;
Data data[n]; long long num1=,num2=;
for(long long i=;i<n;i++){
data[i].zua=num1;
data[i].zub=num2;
if((i+)%a==){
++num1;
}
if((i+)%b==){
++num2;
}
}
long long result=;
for(long long i=;i<n;i++){
for(long long j=i;j<n&&j<i+a;j++){
if(data[i].zua==data[j].zua&&data[i].zub!=data[j].zub){
++result;
}
}
}
cout<<result;
}

那么就用一个数组来实现它:

 #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; int main(){
int a,b,n;
cin>>a>>b>>n;
long long result=;
bool qwe;
for(int i=;i<n;i=i+a){
int yb=i/b,k=,cur;
qwe=; for(int j=i+;j<i+a&&j<n;j++){
int yb2=j/b;
if(yb2==yb) continue;
if(!qwe){
cur=yb2;
k=j-i;
qwe=;
}
if(yb2!=cur){
k=j-i;
cur=yb2;
}
result+=k;
}
}
cout<<result<<endl;
}
 
 
 

ural Infernal Work的更多相关文章

  1. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  2. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  3. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  4. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  5. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  6. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  7. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  8. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

  9. ural 2065. Different Sums

    2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...

随机推荐

  1. Hybrid框架UI重构之路:一、师其长技以自强

    这两年在支撑公司的Hybrid框架的运维发展,让人确认这种移动开发方式确实是一条不错的路.混合应用这种开发方式降低开发难度,极大的提高开发效率,最重要的一点效果可以接近原生应用.框架的本身是需要持续不 ...

  2. JavaScript实战-菜单特效

    以下是我自己用原生JS写的各种菜单特效,虽然网上一搜一大堆,但我还是喜欢自己来写一写! 这是上一篇:JavaScript实战(带收放动画效果的导航菜单) 下面是经过优化后的完整代码,优化了CSS样式. ...

  3. SharePoint基于windows验证的如何通过组策略实现IE自动以当前域账号登录SP站点

    通过组策略实现IE自动以当前域账号登录SP站点 1. 在运行中运行MMC,启动"组策略对象编辑器". 如下图: 找到组策略如下图: 找到域 点右键编辑 找到如下图: 找到[计算机配 ...

  4. Ubuntu Server 14.04升级Ubuntu Server 16.04

    Ubuntu Server 14.04升级Ubuntu Server 16.04 :转 http://blog.csdn.net/chszs 1.终端下执行命令 $ sudo apt-get upda ...

  5. 【代码笔记】iOS-点击搜索按钮,或放大镜后都会弹出搜索框

    一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "CLHSearchBar.h ...

  6. Android按键事件处理流程 -- KeyEvent

    刚接触Android开发的时候,对touch.key事件的处理总是一知半解,一会是Activity里的方法,一会是各种View 中的,自己始终不清楚到底哪个在先哪个在后,总之对整个处理流程没能很好的把 ...

  7. Windows下配置Git服务器和客户端 超全

    为了配合Redmine使用,特地用Git来做版本控制. Git Candy© 是一个基于ASP.NET MVC的Git分布式版本控制平台,Git Candy的目标是轻松干掉Bonobo,逐渐追赶Git ...

  8. wpf开发桌面软件记录

    我的开发环境是win7,vs2013,sql2012,用wpf开发了一个很简单的桌面软件,用Installshield制作的安装包,安装包包含了.framework4.5,在自己电脑上测试正常,想着挺 ...

  9. ARC下的所有权修饰符

    ARC有效时,id类型必须加上所有权修饰符 下面为三种等效的声明,为了便于和二级指针的情况联系起来,采用第一种. NSError * __weak error = nil; NSError __wea ...

  10. mysql执行计划

         烂sql不仅直接影响sql的响应时间,更影响db的性能,导致其它正常的sql响应时间变长.如何写好sql,学会看执行计划至关重要.下面我简单讲讲mysql的执行计划,只列出了一些常见的情况, ...