UVa 10642 - Can You Solve It?
生活随笔
收集整理的這篇文章主要介紹了
UVa 10642 - Can You Solve It?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:二維平面上的整數點。用路徑鏈接起來(0,0)->(1。0)->(0。1)->(2,0)->..
? ? ? ? ? ? 給你兩點坐標。求兩點間步長(在路徑上的距離)。
分析:簡單題。
? ? ? ? ? ? 我們發現點是依照x+y的遞增序。且y的遞增序(x+y同樣時)排列的;
? ? ? ? ? ? 所以每一個點相應的路徑上的位置為:(x+y)*(x+y+1)/ 2 + y。
說明:注意使用long long防止數據溢出。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath>using namespace std;int main() {int T,x1,y1,x2,y2;while (~scanf("%d",&T))for (int t = 1 ; t <= T ; ++ t) {scanf("%d%d%d%d",&y1,&x1,&y2,&x2);long long n = (x1+y1)*(x1+y1+1LL)/2LL+y1;long long m = (x2+y2)*(x2+y2+1LL)/2LL+y2;printf("Case %d: %lld\n",t,m-n);}return 0; }轉載于:https://www.cnblogs.com/brucemengbm/p/6710169.html
總結
以上是生活随笔為你收集整理的UVa 10642 - Can You Solve It?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 报错 POST http://192.1
- 下一篇: 数据结构栈的构造