codeforce-round760-div3

题目链接:Problem – A – Codeforces

题意:给你一个数组大小为7的数组,在这个数组内有元素a,b,c满足a+b,a+c,b+c,a+b+c为另外四个元素,求出满足这个关系的一组a,b,c,直接输出即可。这里直接枚举就好了,代码如下:

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> su(int a, int b, int res) {//开始以为数组范围很大,开了个函数来计算
	vector<int>c;
	c.push_back(a + b), c.push_back(b+res), c.push_back(a + res);
	sort(c.begin(), c.end());
	return c;
}
int main() {
	int n;
	cin >> n;
	while (n--) {
		int q[7];
		for (int i = 0; i < 7; i++)cin >> q[i];
		sort(q, q + 7);//其实不用排序,输入顺序就是从小到大
		int a1 = q[0];//分析一下第一位必定在三个数里,最后一位可以不用考虑
		for (int i = 1; i < 6; i++) {
		    int fl=0;//标记位,如果为1说明满足条件
			for (int j = i + 1; j < 6; j++) {
				vector<int>e,temp;
				e = su(q[i], q[j], a1);
				for (int te = 1; te < 6; te++) {
					if (te == i || te == j)continue;
					else temp.push_back(q[te]);
				}
				if (temp == e) {
					cout << a1 << " " << q[i] << " " << q[j] << endl;
					 fl=1;
					 break;
				}
			}
			if(fl==1)break;//退出内层循环
		}
	}
	return 0;
}

题目链接:Problem – B – Codeforces

题意:由单串推出总串,abbaaba,逐个字符遍历形成ab,bb,ba,aa,ab,已知后面恢复前面,直接从第一个字符串的第二个字符和第二个字符串判定首否来源相同。

代码如下:

#include <iostream>
#include <cstring>
using namespace std;
const int N=105;
string q[N];
int main(){
        int t;
        cin>>t;
        while(t--){
                int n;

                cin>>n;
                for(int i=1;i<=n-2;i++)cin>>q[i];
                string s;
                s+=q[1][0];
                int flag=0;
                for(int i=1;i<=n-3;i++){
                        if(q[i][1]==q[i+1][0])s+=q[i][1];
                        else{
                              s+=q[i][1],s+=q[i+1][0];
                              flag=1;
                        }
                }
                s+=q[n-2][1];//加最后一位
                if(!flag)s+=q[n-2][1];//为了解决字符串缩短问题,如果字符串恢复过程中存在不同的说明字符窜刚好恢复
                cout<<s<<endl;
        }
        return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇