11129 – An antiarithmetic permutation

描述:題目的意思是對0-n之間的數進行變化,,使之任何子序列都不能出現等差數列,1 2 4 3這樣也不行,因為1 2 3也是等差數列,而1 3 4 2卻可以,輸出任何一種即可,所以就採用了遞迴歸併的方法,先分成奇偶數列,然後奇偶數列再次分成奇偶數列,知道不能分為止#include <cstdio>int num[10010],t[10010];void solve(int x,int y){ if(y-x<=1) return; for(int i=x; i<

UVa 10673 – Play with Floor and Ceil

擴充歐幾裡得演算法,直接套模板即可。代碼如下:#include <cstdio>#include <cmath>#include <cstring>void gcd(int a, int b, long long &d, long long &x, long long &y){ if(!b) { d = a; x = 1; y = 0; } else {

UVa 138 – Street Numbers

題目實際就是給你兩個數m、n,使得m、n之間的數之和與1~m之間的數之和相等(不包括m)。即:1+2+...+m-1 == (m+1)+...+n; 因此我們可以套用求和公式,兩邊移項化簡得:2*pow(m,2) = n*(n+1)。因此我們可以得到:m =

10911 – Forming Quiz Teams

描述:集合題目,劉汝佳書上有這道題目,不過他的代碼有點漏洞,需要改一點才能過#include <cstdio>#include <cstring>#include <cmath>int n,t=0;char str[1010];double v[25][2],d[(1<<20)];double min(double x,double y){ return x>y?y:x;}double solve(int x,int y){

UVa 116 – Unidirectional TSP

狀態方程:max{ dp[i+1,j+1], dp[i,j+1], dp[i-1,j+1]},路徑列印也是利用動歸的思想,每個狀態下在保證路徑權值最小的情況下保證起始行數為較小值。代碼如下:#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define inf 0x7FFFFFFFconst int MAXN = 12;const int MAXN2 = 102

UVa 10006 – Carmichael Numbers

打素數表+快速冪模數。題目較簡單,只要數字滿足其不是素數且利用“Fermat test”方法證明所有情況下均滿足,則其為Carmichael Numbers。注意數字範圍,分治求冪模時要用long long。代碼如下:#include <cstdio>#include <cmath>#include <cstring>bool vis[65002];void Is_Prime(int n)//打素數表{ memset(vis, false,

UVa 10183 – How Many Fibs?

求區間[a,b]內斐波那契數的個數,因為最大到了10的100次方,初步遞推一下,10的100次方左右,可達到斐波那契數列的第480項左右,因此用暴力枚舉+大數加法即可。代碼如下:#include <cstdio>#include <cstring>#include <cmath>char fibo[480][105];void Fibonacci(char *a, char *b, char *c)//斐波那契數列打表{ int len =

10006 – Carmichael Numbers

描述:需要篩選和冪模數,要不然普通演算法就會逾時,只有合數並且滿足所有的a(2<a<n)a^n%n=a才能輸出The number %d is a Carmichael number.,否則輸出%d is normal.#include <cstdio>#include <cstring>#include <cmath>bool prime[65005];void solve(){ memset(prime,0,sizeof(prime));

UVa 10023 – Square root

大數開平方,本來用從網上查的手動開平方的方法寫的代碼,但中間過程需要用到double型的量存取,結果TLE,調試了一下,原來是double型的量存取長度不夠,換成long double型的量,可以存到10的100次方了,但交上以後依然WA,又調試了半天才發現,當double型量存取數字到18位左右以後,雖然依然可以存取數字,但數位精度已經會有改變,也就是說位元還是那個位元,但實際數字已經不對了。最後還是查的其他人的方法,果斷還是得寫大數。WA代碼:#include

UVa 10397 – Connect the Campus

因為已經有部分建築用電線連起來了,要求還需要多少電線才可以將全部建築連起來,只需要將用電線連起來的城市之間的距離設為0,再用Kruskal。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;const int

10245 – The Closest Pair Problem

描述:剛開始直接逾時,後來改了一點,居然過了#include <cstdio>#include <cmath>#define N 10010double num[N][2];int main(){ // freopen("a.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { if(!n) break; double sum=100000000,count;

UVa 10099 The Tourist Guide

求兩點之間所有路徑中最小單元間距的最大值,既可以仿照UVa10048用kruskal最大產生樹的原理求,又可以用Floyd演算法求。代碼如下(Floyd演算法):#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int vis[101][101];const int

UVa 10038 – Jolly Jumpers

每相鄰的兩個數之間求差,若這n個數的所有的差值正好滿足1~(n-1),則輸出“Jolly”,否則輸出“Not Jolly”。代碼如下:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;bool vis[3000];int a[3000], num;bool Judge(){

UVa 10369 – Arctic Network

有s個衛星,剩下的全用無線裝置(求剩下的其無線電點中最大的兩個無線電之間的距離),實際就是是求最小產生樹中第p-s大的邊的長度,類比kruskal即可,注意其資料量是1000,而不是100。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using

UVa 11121 – Base -2

將一個十進位轉化為-2進位的數。同樣求餘數,當n%-2<0時,所得餘數m應 m -= base; (base=-2),替代後減少的那部分值需要加回來,即:所得商+1。代碼如下:#include <cstdio>#include <cstring>#include <cmath>int main(){#ifdef test freopen("sample.txt", "r", stdin);#endif int t, n, bi, cct=0;

UVa 10608 – Friends

並查集,實際就是統計圖中最大連通分支中節點的個數。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;const int MAXN = 30002;int friends[MAXN], p[MAXN];int

10651 – Pebble Solitaire

描述:對於這道題,實在想不出如何用動規,所以就直接bfs#include <cstdio>#include <cstring>char s[5010][15];int main(){ // freopen("a.txt","r",stdin); int n,flag; while(scanf("%d",&n)!=EOF) for(int i=0; i<n; i++) { scanf("%s",

UVa 10801 – Lift Hopping

根據題意,以每一層樓為頂點,每個電梯可以到達的兩層樓之間的秒數為每一條邊的權值,以此構建一個無向圖。然後利用dijkstra求出最短的時間,注意每次轉乘電梯需要等待60s(因為同一個電梯上的樓層是相互可達的,所以我們只有通過另外一個電梯找到了更小的搭乘時間時候我們才會執行鬆弛操作),因此每轉一個定點需要加60s時間(注意初始定點不需要60s的等待)。代碼如下:#include <iostream>#include <algorithm>#include

10051 – Tower of Cubes

描述:麻煩的題,需要記錄走過的路程,而且和最短路還有些車別#include <cstdio>struct cube{ int val; int sum; int no; int x; int y;};cube v[510][6];char str[6][7]= {"front","back","left","right","top","bottom"};int main(){ //freopen("a.txt","r",stdin);

UVa 10791 – Minimum Sum LCM

分解質因子的一個題,將最小公倍數分解質因子,最小的和sum便為各個質因子的相應次方數之和。此題痛點在於幾個特殊的情況的處理:(1)當N = 1時,應輸出2(1*1=1,sum=1+1=2);(2)當N是素數的時候,輸出N+1(N*1=N,sum=N+1);(3)當只有單質因子時,sum=質因子相應次方+1;(4)當N=2147483647時,它是一個素數,此時輸出2147483648,但是它超過int範圍,應考慮用long long。代碼如下:#include

總頁數: 61357 1 .... 13820 13821 13822 13823 13824 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.