ural Infernal Work
2015-10-03 15:23
302 查看
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 a, b, n (1 ≤ a, b ≤ 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
首先看第一种方法(超出空间限制):
那么就用一个数组来实现它:
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 a, b, n (1 ≤ a, b ≤ 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 ; long long num1=1,num2=1; for(long long i=0;i<n;i++){ data[i].zua=num1; data[i].zub=num2; if((i+1)%a==0){ ++num1; } if((i+1)%b==0){ ++num2; } } long long result=0; for(long long i=0;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=0; bool qwe; for(int i=0;i<n;i=i+a){ int yb=i/b,k=1,cur; qwe=0; for(int j=i+1;j<i+a&&j<n;j++){ int yb2=j/b; if(yb2==yb) continue; if(!qwe){ cur=yb2; k=j-i; qwe=1; } if(yb2!=cur){ k=j-i; cur=yb2; } result+=k; } } cout<<result<<endl; }
相关文章推荐
- HTML5 Form Data 对象的使用-jQuery
- javascript 中检测数据类型的方法
- 三种样式表插入方法
- 解决jetty runner锁定js
- javascript基础(下)
- JSon 事件格式化
- JSP/Servlet 工作原理
- Enum:Smallest Difference(POJ 2718)
- javascript 中的类数组和数组
- 浅谈HTML5之四:全局属性
- caffe在笔记本ubuntu14.04 64位下的无GPU安装
- ExtJS4 根据分配不同的树形菜单在不同的角色登录后
- 浅谈HTML5之三:新增的属性和废除的属性
- js文件引入顺序问题
- ExtJS得知--------Ext.Element学习的查询方法(示例)
- HDOJ 5479 Scaena Felix
- html学习之一
- 151003-动起来-Javascript
- react native windows开发环境搭建(一)
- JS(ajax笔记)