(Incomplete) UVa 138 Street Numbers

方法:暴力

设home的序号为n,街尾序号为N,列出方程 (n-1)*n/2 = (N+n+1)*(N-n)/2, 化简得 2*n*n = (N+1)*N。枚举N再检查是否有解。可以直接求,或者打表。

code:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <unordered_map>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline ‘\n‘

#define test if(1)if(0)cerr
using namespace std;
  using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double pi = acos(-1.0);

vector<ll> ans;

int main()
{
    ll i = 2;
    while (ans.size() < 10)
    {
        ++i;
        ll n = sqrt((i+1)*i/2);
        if (n * n == (i+1)*i/2)
            ans.pb(i);
    }
    for (auto i : ans)
    cout << setw(10) << (ll) sqrt((i+1)*i/2) << setw(10) << i << newline;
}

  

  

据说可以转化成佩尔方程,待学习。

时间: 2024-10-04 06:56:13

(Incomplete) UVa 138 Street Numbers的相关文章

UVA - 138 - Street Numbers (简单数论)

题目传送:UVA - 138 思路:题意好难懂,看了半天,还是搜了题解才搞懂题意,真是给英语跪啦 m在家的位置,而n是最后一个位置,直接输出前10组满足1~m-1的和 == m+1 ~ n的和,这是题意: 然后通过题意可以得到n*(n+1)/2 - m - m*(m-1)/2 = m*(m-1)/2; 化简可得2*m*m = n*(n+1); 然后可以通过枚举n来求得m,看m是否为整数(可由double到int判断),是整数则满足情况 打表代码: #include <cstdio> #incl

POJ 1320 Street Numbers 【佩尔方程】

任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3181   Accepted: 1776 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the

UVA - 12046 Great Numbers

Description Problem G - Great Numbers In this problem you have to count the number of great numbers of length n. Here a great number must have the following property: the number must be divisible by all of its decimal digits. it does not contain any

(Incomplete)UVa 701 The Archeologist&#39;s Dilemma

方法:对数,暴力 我们需要求出最小的e,是的存在一个i > len(n) , 满足   floor[2^e/ (10^i)]= n, 即 n*10^i < 2^e < (n+1)*10^i.对两边同时取log10 (以10为底的对数,记作lg),得到 lg(n) + i < e*lg(2) < lg(n+1) + i. 注意len(n) = (int) lg(n)+1, 之前一个条件 i > len(n) 可以转化为 i > lg(n)+1,  然后暴力枚举即可.

UVA 610 - Street Directions(割边)

UVA 610 - Street Directions 题目链接 题意:给定一个无向图,要求把尽可能多的边定向,使得形成一个强连通图,输出定向后的图,不能定向的边就变成两条有向边 思路:找出割边,只有割边是需要定成两条的,其他的双连通分量中,边肯定都可以定向,然后在dfs不经过割边打印路径,最后在打印出割边(拆成两条) 代码: #include <cstdio> #include <cstring> #include <vector> using namespace s

UVA - 471 Magic Numbers

Description  Magic Numbers  Write a program that finds and displays all pairs ofintegers and such that: neither nor have any digits repeated; and , where N is a given integer; Input and Output The input file consist a integer at the beginning indicat

Uva - 12050 Palindrome Numbers【数论】

题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: 1 #include <bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 const int maxn=3010; 5

Street Numbers

 Street Numbers A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the str

UVA 136 Ugly Numbers

原题代号:UVA 136 原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=72 题目原题: Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5,