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. pdo mysql错误:Cannot execute queries while other unbuffered queries are active

    运行环境:PHP 5.5.30-x64,MYSQL  5.6.27 错误代码:Cannot execute queries while other unbuffered queries are act ...

  2. 【思维导图】Fiddler学习笔记

    最近在学习Fiddler这款工具,边学边画了如下的思维导图,可以方便自己对这款工具有一个全面的了解. 软件介绍(摘自百度百科):Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电 ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q9-Q12)

    Question 9 You are designing an external binary large object (BLOB) store provider by implementing t ...

  4. Android Design Principles

    Android Design Principles Enchant Me Delight me in surprising ways 用惊奇的方式取悦用户 漂亮的界面,仔细放置的动画,一个恰到时机的音 ...

  5. Android Animation学习(六) View Animation介绍

    Android Animation学习(六) View Animation介绍 View Animation View animation系统可以用来执行View上的Tween animation和F ...

  6. Android studio .9图片造成的错误总结

    前言,今天早晨遇到一个很奇葩的问题,导致我花费了很长的时间来解决.从eclipse 项目里复制过来4张.9图片,粘贴到android studio 项目里, 一运行发现报错,开始是 找不到这几张.9图 ...

  7. 【读书笔记】iOS网络-保护网络传输

    一,验证服务器通信. 二,HTTP认证. 手机银行应用有两种认证模式:标准验证与快速验证.标准验证只是提示用户输入用户名与密码,而快速验证则让用户注册设备,然后使用PIN进行验证,每次验证时无需用户名 ...

  8. 记一次eclipse无法启动的排查过程

    起因是本地为开发工程打包,总是提示 source 1.3 不支持注释.enum等等,但询问开发开发表示自己本地打包正常. 于是排查版本问题.开发的jdk是1.6版本,自己的是1.7,于是想要不降级吧, ...

  9. jquery实现当前页面按钮点击全屏,点击退出全屏

    var fullscreen=function(){ elem=document.body; if(elem.webkitRequestFullScreen){ elem.webkitRequestF ...

  10. 清除ASPX页面中的meta:resourceKey="[a-zA-Z0-9]+"

    在替换对话框中,选中“使用正则表达式”, 被替换内容,使用 meta:resourceKey="[a-zA-Z0-9]+" 然后替换整个文档就可以了.