SRM 480 DIV 2

1 水题。。。非常松的限制条件,如果都去掉的话,或许会成为challenge的一道好题

2 非常恶心的问题,一个trick把我给绕进去了。。不能线序的遍历一遍,需要不断设置,不断扩充未完成的集合,并附设标记位

3 又是一道恶心的题目。。。这种1000分的题目,一定不要放弃,不断思考,一定会有结果的。。

This problem can be solved greedily with the following powerful observation.

Let X1, X2, X3, ..., XN be the numbers. We must allocate them in the encrypted string in some order. Suppose that Xi is the last number allocated number in this order. Then, it is optimal to allocate the rest of the numbers starting from the smallest one and in increasing order. That is, if Xi is the last number allocated, then the smallest possible length of the encrypted string is partialsolution(sortascending(X1,X2,...,X(i-1),X(i+1),...,XN) + Xi).

We'll see that this is true by contradiction. Suppose there exist j and k (both are not equal to i), j < k such that Xj > Xk and the representative of Xj is to the left of the representative of Xk. The proof will be complete if we show that we can swap the locations of the representatives of these two numbers, since we can then apply this until all numbers except Xi are sorted. We suppose that Xj is allocated at position 2^Pj and Xk is allocated at position 2^Pk. Since Xk < Xj, it follows that Xk can be placed in the former position of Xj. Now, since the length of Xj must be less than 2^Pk (since otherwise Xk cannot be originally allocated at 2^Pk), we can place Xj in the former position of Xk without affecting the position 2^(Pk+1). Hence, the proof is complete.

解答,代码写的真的是非常的漂亮!!

// END CUT HERE
#line 5 "SignalIntelligence.cpp"

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

// BEGIN CUT HERE

//Begin Sosi TopCoder

//const double EPS=1e-11;

//const double PI=acos(-1.0);

//const short INF=32767,NF= -32768;

//const int INF=2147483647,NF= -2147483648;

//const long long INF=9223372036854775807,NF=-9223372036854775808;

//const long double INF=99999999.99999999;

//Numberic Functions

//template T gcd(T a,T b){ if(a<0) return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

//template T lcm(T a,T b){ return a*(b/gcd(a,b));}

//template inline vector > factorize(T n)

//   {vector > R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}

//   i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}

//template inline bool isPrimeNumber(T n)

//   {if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}

//template inline T eularFunction(T n)

//   {vector > R=factorize(n);T r=n;for (int i=0;i

//Translator

//template string toString(T n){ostringstream ost;ost<

//int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toInt(

//long long toInt64(string s){long long r=0;istringstream sin(s);sin>>r;return r;}

//double toDouble(string s){double r=0;istringstream sin(s);sin>>r;return r;}//NOTES:toDouble(

//template void stoa(string s,int &n,T A[]){n=0;istringstream sin(s);for(T v;sin>>v;A[n++]=v);}

//template void atos(int n,T A[],string &s){ostringstream sout;for(int i=0;i 0)sout<<' ';sout<

//template void atov(int n,T A[],vector &vi){vi.clear();for (int i=0;i

//template void vtoa(vector vi,int &n,T A[]){n=vi.size();for (int i=0;i

//template void stov(string s,vector &vi){vi.clear();istringstream sin(s);for(T v;sin>>v;vi.push_bakc(v));}

//template void vtos(vector vi,string &s){ostringstream sout;for (int i=0;i 0)sout<<' ';sout<

//Fraction

//template struct Fraction{T a,b;Fraction(T a=0,T b=1);string toString();};

//template Fraction ::Fraction(T a,T b){T d=gcd(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}

//template string Fraction ::toString(){ostringstream sout;sout< <<"/"<

//template Fraction operator+(Fraction p,Fraction q){return Fraction (p.a*q.b+q.a*p.b,p.b*q.b);}

//template Fraction operator-(Fraction p,Fraction q){return Fraction (p.a*q.b-q.a*p.b,p.b*q.b);}

//template Fraction operator*(Fraction p,Fraction q){return Fraction (p.a*q.a,p.b*q.b);}

//template Fraction operator/(Fraction p,Fraction q){return Fraction (p.a*q.b,p.b*q.a);}

//STL

//bool comp(T A,T B){return A

//do{ } while(next_permutation(T.begin(), T.end()));

//int dirx[]={1,0,-1,0};

//int diry[]={0,-1,0,1}; //clockwise

//int dirx[]={1, 1, 0,-1,-1,-1,0,1};

//int diry[]={0,-1,-1,-1, 0, 1,1,1}; //clockwise

//End Sosi TopCoder

// END CUT HERE

class SignalIntelligence
{
public:
    long long encrypt(vector numbers)
    {
        int n = numbers.size();
        long long best = -1;
        for (int i=0;i
        { // every possible last number
            //printf("try %d as last one/n", numbers[i]);
            vector numbers2;
            for (int j=0;j =i)?1:0)]);
            sort(numbers2.begin(),numbers2.end());
            //printf("numbers left:");
            //for (int j=0;j             //printf("/n");
            long long pos = 1, npos = pos;
            for (int j=0;j
            {
                //printf("set %d at pos %d/n", numbers2[j], pos);
                npos = pos;
                while (pos + numbers2[j] >= npos) npos *= 2;
                pos = npos;
            }
            //printf("would be %d long/n/n",pos + numbers[i]-1);
            if (best == -1 || npos + numbers[i]-1 < best) best = npos + numbers[i]-1;
        }
        return best;
    }

    //$CARETPOSITION$

    // BEGIN CUT HERE
public:
    void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); }
private:
    template string print_array(const vector &V) { ostringstream os; os << "{ "; for (typename vector ::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '/"' << *iter << "/","; os << " }"; return os.str(); }
    void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "/tExpected: /"" << Expected << '/"' << endl; cerr << "/tReceived: /"" << Received << '/"' << endl; } }
    void test_case_0() { int Arr0[] = {1,2,3}; vector Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); long long Arg1 = 8LL; verify_case(0, Arg1, encrypt(Arg0)); }
    void test_case_1() { int Arr0[] = {4,4,2,2}; vector Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); long long Arg1 = 19LL; verify_case(1, Arg1, encrypt(Arg0)); }
    void test_case_2() { int Arr0[] = {1000000000,1000000000,1000000000,1000000000,1000000000,
        1000000000,1000000000,1000000000,1000000000,1000000000,
        1000000000,1000000000,1000000000,1000000000,1000000000,
        1000000000,1000000000,1000000000,1000000000,1000000000}; vector Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); long long Arg1 = 281475976710655LL; verify_case(2, Arg1, encrypt(Arg0)); }

    // END CUT HERE

};

// BEGIN CUT HERE
int main()
{
    SignalIntelligence ___test;
    ___test.run_test(-1);
    return 0;
}

做题的时候,summer在旁边晃来晃去。。。心烦。。。不过看到最后的代码的实现,的确是非常优美啊!

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值