11121 – Base -2

描述:除-2取餘,餘數為負的時,餘數要減去-2,商要加一#include <cstdio>#include <cmath>int main(){ //freopen("a.txt","r",stdin); int n,t,len; int base[1010]; scanf("%d",&t); for(int p=1;p<=t;p++) { scanf("%d",&n); printf(

UVa 10285 – Longest Run on a Snowboard

算最長路,最長上升子序列的變形。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int dp[101][101], graph[101][101];int n, r, c;int DP(int i, int j){ if(dp[i][j] > 0) return dp[i][j]

UVa 10387 – Billiard

可以發現走過的總的水平距離為與垂直邊碰撞的次數乘以水平邊的長度,即:(a * m),同理總的垂直距離為(b * n)。所以,其弧度為 (a*m)/(b*n) 的反正切值,再轉換為角度,總長度用勾股定理算出來再除以時間,就是速度。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>using namespace

幾種選擇全排列實現的效率

統計幾種選擇全排列實現的效率,所謂選擇全排列,如:在4個球之間選擇2個球,其全排列數為 6 。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cmath>using namespace std;int cnt, cct, tot, n, k;char a[25];void test_1(int cur){

UVa 10192 – Vacation

最長公用子序列。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define Maxn 102int main(){#ifdef test freopen("input.txt", "r", stdin);#endif int dp[Maxn][Maxn]; int len1,

UVa 10341-Solve It

是個單調遞減的函數,然後用二分法做,迴圈取估值 ~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>using namespace std;int main(){#ifdef test freopen("sample.txt","r",stdin);#endif

HDU 1735 – 字數統計

貪心,只要開頭有兩個0,則需要判斷其上一行最後有多少個連續的0,按上一行最後處0的數量由大到小排序(因為要令破壞字數最小,因此需要令其可轉換為1(即可確定的字數)的0的數量最大)。最後特殊處理一下,第一行開頭和最後一行結尾的0即可。代碼如下:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace

UVa 357 – Let Me Count The Ways

完全背包問題。代碼如下:#include <iostream>#include <cstdio>using namespace std;long long dp[30055];int coin[5] = {1, 5, 10, 25, 50};int main(){ int num; dp[0] = 1; for(int i=0; i<5; ++i) { for(int j=0; j<30001; ++j)

UVa 10340 – All in All

字串匹配,滿水的一個題了,不過記得數組得開大點,還有讓我比較鬱悶的就是,昨晚交的題,等了得半個小時吧,一直在排隊,一直到今早才判出來 ~代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>using namespace std;char a[100000+2],b[100

HDU 4190 – Distributing Ballot Boxes

貪心+二分,最大值最小化問題。利用投票箱b的值是一定的,將投票數進行二分,使得算出的投票箱數始終為b。代碼如下:#include<cstdio>int city[500001];int main(){ int n, b; while(scanf("%d%d", &n, &b)) { int Max = 0, l, r, mid; if(n==-1 && b==-1) break;

UVa 10041 – Vito’s Family

這個題在上機時敲的,乍一看好簡單(其實確實也不難,就是中位元做差求和的問題),本來說要秒殺的,結果WA了好幾遍,仔細分析後又是沒讀透題意,把當房屋為偶數時的中位元的情況當成了是中間兩個數之和的一半了,為此還用double型的量寫的好長(白費力氣了),實質上它是不允許“另外建房子的”,也就是說是在已知家庭的家庭中挑一個家庭住,偶數時只要在中間兩個家庭中選一個就好(其實選哪個算出的值都一樣的), 改完後AC了

10370 – Above Average

清早一個水題,美好的一天由此開始了 ~統計平均分以上的學生個數。代碼如下:#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>using namespace std;int main(){#ifdef test freopen("sample.txt","r",stdin);

993 – Product of digits

描述:題意就是從1-9之間找出一堆數相乘的積就是輸入的數值,如果沒有,就輸出-1#include <cstdio>#include <cstdlib>int main(){ // freopen("a.txt","r",stdin); int n,x; scanf("%d",&n); while(n--) { scanf("%d",&x); if(x>=10) {

UVa 562 – Dividing coins

題意為將硬幣分成倆堆使兩堆硬幣的差值最小。0-1背包,可以將硬幣能湊成的所有和都計算出來,然後從sum/2(sum為所有硬幣的和)開始向0探尋,直到找到所給硬幣能湊成的最大的硬幣和 i,然後其最小差便為sum-2*i。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int Maxn = 102

UVa 10382 – Watering Grass

實際上就是區間覆蓋的變形,顯然圓形能覆蓋的矩形地區為圓形與總地區相交的長度,這就將圓形全部轉換成了線段,這樣就可以按區間覆蓋來做了。但是這個題比較噁心的地方是卡了比較嚴格的精度,這裡需要額外注意一下。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>using namespace std;struct

UVa 10130 – SuperSale

0-1背包,最後將每個人的最大價值都加起來,就是總的最大價值。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int p[1002], w[1002], mw[102], dp[32];int main(){#ifdef test freopen("input.txt", "r", stdin);#

UVa 10148 – Advertisement

一個區間取點問題,按右端點排序。從右端開始標註,保證每段區間都有K個標註點,小於K的區間則保證其區間的點全部被標註,在標註時注意因為範圍是-10000~10000,因此需要用一個20000的數組存,需將整體範圍往右移動10000(例:標註-10000為a[0] = 1,標註0為a[10000] =

UVa 624 – CD

計算磁帶能裝下的最大音樂的時間長度。0-1背包的變形,注意因為需要按從前往後的順序列印路徑,所以在分階段DP時,需要從後往前。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int Maxn = 20;int cd[Maxn], dp[Maxn*500];bool

UVa 531 – Compromise

最長公用子序列,列印路徑,注意格式的列印。代碼如下:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;char w1[100][31], w2[100][31];int dp[101][101], path[101][101];void Print(int sum, int i, int j)//遞迴列印路徑{

UVa 757 – Gone Fishing

貪心+暴力,從近至遠依次枚舉可以到達的釣魚地點,用總時間減去中途消耗的時間,這樣就可以將其當成在各個釣魚地點之間隨意轉移(實際題目中給出是單方向前行的),然後在已到達的最遠的釣魚地點之內的所有釣魚地點上按每次釣最大值的魚做貪心,若時間用不完,則剩餘時間加到第一個釣魚地點上。注意,釣魚地點最初的釣魚值可能為零。代碼如下:#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio&g

總頁數: 61357 1 .... 13817 13818 13819 13820 13821 .... 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.