TopCoder SRM 144 DIV 1

开始做TopCoder,英语不好真是拙计啊,光是找到题库和知道怎么提交就用了很长时间。。然后随便找了道貌似简单的,读懂题意又用去很长时间,看来C++,python什么的都不重要,先学好英语才是关键啊。。

另外TopCoder的提交方式比较特别,跟一般OJ上的输入输出不太一样,还要用到class相关的东西,这又是一大坑,不过比英语坑好填一些,慢慢来吧。

先贴一题,虽然过了,还是没怎么搞懂这种submit方式。

还有TC每道题的分数是随着时间逐渐降低的,最低可降到30%,我这第一题虽然是水题,但研究返回string和使用class就花了好长时间,所以300point的题最后只拿98point。。丢人


300point : Problem Statement for BinaryCode

#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class BinaryCode{
	public:
		vector<string> DeCode(string message){
			vector<string> result;
			result.push_back(decode('0',message));
			result.push_back(decode('1',message));
			return result;
		}
	private:
		string decode(char first, string message){
			string res;
			int len = message.length();
			if(len == 1){
				if(message[0] == first)
					res = message;
				else
					res = "NONE";
			}
			else{
				for(int i = 0; i < len; i++){
					if(i == 0){
						res += first;
						res += message[i]-res[i]+'0';
					}
					else if(i == len-1){
						if(res[i]-'0'+res[i-1] != message[i])
							res = "NONE";
					}
					else{
						res += message[i]-res[i]+'0'-res[i-1]+'0';
					}
					if(res[i] != '0' && res[i] != '1'){
						res = "NONE";
						break;
					}
				}
			}
			return res;
		}
};

550point:Problem Statement for Lottery

这道题主要是排列组合,难点在于对n个数可重复的m个数进行升序排列,公式是C(m,n+m-1)

代码还是比较简单的,不过时间又快用尽了,才拿到165point。。。


#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

struct Rule{
	string name;
	int choices, blanks;
	char sorted, unique;
	long long int odd;
	bool operator < (const Rule &b) const{
		if(odd != b.odd) return odd < b.odd;
		return (name < b.name);
	}
};
class Lottery{
	public:
		vector<string> sortByOdds(vector<string> rules){
			vector<string> result;
			Rule R[51];  int i = 0;
			while(!rules.empty()){
				string buf = rules.back();
				rules.pop_back();
				R[i++] = calOdd(buf);
			}
			sort(R,R+i);
			for(int j = 0; j < i; j++)
				result.push_back(R[j].name);
			return result;
		}
	private:
		long long int A(int n, int m){
			long long int res = 1;
			for(int i = 0; i < m; i++)
				res *= n-i;
			return res;
		}
		long long calC(int n, int m){
			long long int C[110][9];
			for(int i = 1;i <= n; i++){
				for(int j = 0; j <= m; j++){
					if(j == 0 || j == i)
						C[i][j] = 1;
					else
						C[i][j] = C[i-1][j-1]+C[i-1][j];
				}
			}
			return C[n][m];
		}
		Rule process(string a){
			Rule res;
			int i = a.length()-1, buf = 0, mid = 1;
			res.unique = a[i]; i--; i--;
			res.sorted = a[i]; i--; i--;
			while(a[i] != ' '){
				buf += (a[i]-'0')*mid;
				mid *= 10;
				i--;
			}
			res.blanks = buf; buf = 0; i--; mid = 1;
			while(a[i] != ' '){
				buf += (a[i]-'0')*mid;
				mid *= 10;
				i--;
			}
			res.choices = buf; i--;
			res.name = a.substr(0,i);
			return res;
		}
		Rule calOdd(string a){
			Rule buf = process(a);
			int n = buf.choices, m = buf.blanks;
			long long int res = 0;
			if(buf.sorted == 'T' && buf.unique == 'T')
				res = calC(n, m);
			else if(buf.sorted == 'F' && buf.unique == 'T')
				res = A(n, m);
			else if(buf.sorted == 'F' && buf.unique == 'F')
				res = pow(n, m);
			else if(buf.sorted == 'T' && buf.unique == 'F')
				res = calC(n+m-1,m);
			buf.odd = res;
			//printf("%d %d %c %c %lld",buf.choices,buf.blanks,buf.sorted,buf.unique,buf.odd);
			cout << buf.name << endl;
			return buf;
		}
};



内容概要:本文详细探讨了双馈风力发电机(DFIG)在Simulink环境下的建模方法及其在不同风速条件下的电流与电压波形特征。首先介绍了DFIG的基本原理,即定子直接接入电网,转子通过双向变流器连接电网的特点。接着阐述了Simulink模型的具体搭建步骤,包括风力机模型、传动系统模型、DFIG本体模型和变流器模型的建立。文中强调了变流器控制算法的重要性,特别是在应对风速变化时,通过实时调整转子侧的电压和电流,确保电流和电压波形的良好特性。此外,文章还讨论了模型中的关键技术和挑战,如转子电流环控制策略、低电压穿越性能、直流母线电压脉动等问题,并提供了具体的解决方案和技术细节。最终,通过对故障工况的仿真测试,验证了所建模型的有效性和优越性。 适用人群:从事风力发电研究的技术人员、高校相关专业师生、对电力电子控制系统感兴趣的工程技术人员。 使用场景及目标:适用于希望深入了解DFIG工作原理、掌握Simulink建模技能的研究人员;旨在帮助读者理解DFIG在不同风速条件下的动态响应机制,为优化风力发电系统的控制策略提供理论依据和技术支持。 其他说明:文章不仅提供了详细的理论解释,还附有大量Matlab/Simulink代码片段,便于读者进行实践操作。同时,针对一些常见问题给出了实用的调试技巧,有助于提高仿真的准确性和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值