題目連結 給出一個非減序的數組a[n], 然後得到s=2^a1+.……+2^an, 要使s為2^v -1,需要在數組中添加幾個數。 我的思路是這樣的,由2^a+2^a = 2^(a+1)可知,如果有兩個連續的數a,我們可以把他們合并為a+1放入集合中,使集合中沒有重複的數,我可以用stl裡的set。如果想要滿足題目中的要求,集合中必須有最大那個數個元素,缺多少就可以計算出來了。代碼://codeforces 305 C. Ivan and Powers of Two//201
A.Ilya and Bank AccountIlya得到了一個禮物,可以在刪掉銀行賬戶最後和倒數第二位的數字(賬戶有可能是負的),也可以不做任何處理。//codeforces 313A //2013-05-31-13.47#include <stdio.h>#include <algorithm>using namespace std;int main(){ int n; scanf("%d", &n); if (n) {
///////////////////////////////////////////////////////////////////////////////////////////////////遊戲中用0表示空地,1表示人物,2表示箱子,3表示目的地,6表示圍牆//本程式由VC++6.0開發,採用了easyx函數庫,請到http://www.easyx.cn/網站下載//作者:sambrown from zzu 感謝網友:自然向日葵 ///////////////////////////
#include <stdio.h>#include <string.h>int n, a[100];int used[100];int num[100];void dfs( int x ){int i;if( x >= n ){for( i = 0; i < n; i++ )printf( "%d ", num[i] );printf( "\n" );}else{for( i = 0; i < n; i++ )if( !used[i] ){num[x]
最近的項目用到了matlab,但是由於考慮到要與其他的項目合成,所以不能直接用matlab,所以就想到了能不能把matlab寫成的函數編譯成一個dll,供C#調用,所以網上查了點資料研究了一下matlab與C#的混合編程,記錄一下:首先在matlab中寫好你自己實現的函數,例如假設 function result = myTest (paramA, paramB),把你的.m檔案編寫完以後,在matlab控制台裡輸入deploytool,彈出配置視窗,選擇.net
題目連結A.Yaroslav and Permutations題意: n個元素的數組,每個元素不超過1000,可以交換相鄰兩個元素,問是否可以在有限次的操作之後使得相鄰兩個元素的值不相同。#include <stdio.h>#include <string.h>int cnt[1005];int main(){ int n, a; while (scanf("%d", &n) != EOF) { memset(cnt, 0,