Coder-Strike 2014 - Finals (online edition, Div. 2)

本文介绍了解决两个有趣的问题的方法:一是帮助Pasha将苹果公平地分配给两只仓鼠,确保每只仓鼠只能获得自己喜欢的苹果;二是判断一个单词是否为镜像单词,即该单词能在镜中完美反射自己。
A. Pasha and Hamsters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples.

Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.

Input

The first line contains integers n, a, b (1 ≤ n ≤ 100; 1 ≤ a, b ≤ n) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.

The next line contains a distinct integers — the numbers of the apples Arthur likes. The next line containsb distinct integers — the numbers of the apples Alexander likes.

Assume that the apples are numbered from 1 to n. The input is such that the answer exists.

Output

Print n characters, each of them equals either 1 or 2. If thei-h character equals 1, then thei-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.

不解释,直接上代码:

void Solution()
{
	while(cin >> n >> a >> b)
	{
		CLS(ret, 0);
		REP(i, a)
			cin >> a1[i];
		REP(i, b)
			cin >> a2[i];
		REP(i, a)
		{
			ret[a1[i]] = 1;
		}
		REP(i, b)
		{
			ret[a2[i]] = 2;
		}
		REPA(i, 1, (n+1))
			cout << ret[i] << " ";
		cout << endl;
	}
}

B. Start Up
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?

The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.

There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.

Input

The first line contains a non-empty name that needs to be checked. The name contains at most105 large English letters. The name will be written with the next sans serif font:

Output

Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).

当时写复杂了。。。 还是菜。

char in[NUM];
int len;

bool is_ok(char c)
{
	char temp[] = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'};
	REP(i, 11)
	{
		if(c == temp[i])
			return true;
	}
	return false;
}
void Solution()
{
	while(gets(in)!=NULL)
	{
		bool f = true;
		len = strlen(in);
		REP(i, len)
		{
			if(!is_ok(in[i]))
			{
				f = false;
				break;
			}
		}
		if(f){
			REP(i, (len/2))
			{
				if(in[i] != in[len-1-i])
				{
					f = false;
					break;
				}
			}
		}
		if(f)
			puts("YES");
		else
			puts("NO");
//		getchar();
	}
}

D. Bug in Code
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of then coders on the meeting said: 'I know for sure that eitherx ory did it!'

The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at leastp ofn coders agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?

Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.

Input

The first line contains integers n and p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) — the number of coders in the F company and the minimum number of agreed people.

Each of the next n lines contains two integersxi,yi(1 ≤ xi, yi ≤ n) — the numbers of coders named by thei-th coder. It is guaranteed thatxi ≠ i,  yi ≠ i,  xi ≠ yi.

Output

Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets(1, 2) and(2, 1) are considered identical.

思路: 统计每个人得到票数,然后排序。 穷举找出所有候选人对,算出他们的支持人数。( 这里需要减去同一人同时支持两个人的情况)。 注意:结果可能超过int范围; 枚举的时候需要优化,不然会超时。

代码:

typedef pair<int, int> mpair;

struct _id{
    int id;
    int num;
}r[NUM];

map<mpair, int> store;


int n, p;
long long ans;

bool cmp(_id a, _id b)
{
    if(a.num != b.num)
        return a.num < b.num;
    else
        return a.id < b.id;
}

void Solution()
{
    while(cin >> n >> p)
    {
        ans = 0;
        REPA(i, 1, (n+1))
        {
            r[i].id = i;
            r[i].num = 0;
        }
        REP(i, n)
        {
            int a, b;
            cin >> a >> b;
            (r[a].num) ++;
            (r[b].num) ++;
            int mn = min(a, b);
            int mx = max(a, b);
            mpair temp = make_pair(mn, mx);
            if( store.find(temp) != store.end())
            {
                store[temp] ++;
            }
            else
            {
                store.insert(make_pair(temp, 1));
            }
        }

        for(map<mpair, int>::iterator it = store.begin(); it != store.end(); it++)
        {
            mpair temp = it->first;
            int value = r[temp.first].num + r[temp.second].num;
            if(value >= p && (value - it->second) < p)
                ans --;
        }
        sort(r + 1, r + n + 1, cmp);
        int last = -1, value = 0;
        REPA(i, 1, n)
        {
            if(r[i].num != last)
            {
                REPA(j, (i+1), (n+1)){
                    if(r[i].num + r[j].num >= p)
                    {
                        int temp = n - j + 1;
                        ans += temp;
                        last = r[i].num;
                        if(r[i].num * 2 >= p)
                            value = temp - 1;
                        else
                            value = temp;
                        break;
                    }
                }
            }
            else
            {
                ans += value;
                if(r[i].num * 2 >= p)
                    value --;
            }
        }
        cout << ans << endl;
    }
}

基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的Koopman算子的递归神经网络模型线性化”展开,旨在研究纳米定位系统的预测控制问题,并提供完整的Matlab代码实现。文章结合数据驱动方法与Koopman算子理论,利用递归神经网络(RNN)对非线性系统进行建模与线性化处理,从而提升纳米级定位系统的精度与动态响应性能。该方法通过提取系统隐含动态特征,构建近似线性模型,便于后续模型预测控制(MPC)的设计与优化,适用于高精度自动化控制场景。文中还展示了相关实验验证与仿真结果,证明了该方法的有效性和先进性。; 适合人群:具备一定控制理论基础和Matlab编程能力,从事精密控制、智能制造、自动化或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于纳米级精密定位系统(如原子力显微镜、半导体制造设备)中的高性能控制设计;②为非线性系统建模与线性化提供一种结合深度学习与现代控制理论的新思路;③帮助读者掌握Koopman算子、RNN建模与模型预测控制的综合应用。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现流程,重点关注数据预处理、RNN结构设计、Koopman观测矩阵构建及MPC控制器集成等关键环节,并可通过更换实际系统数据进行迁移验证,深化对方法泛化能力的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值