• 团体程序设计天梯赛 L1-026~L1-030


    L1-026

    思路:

    输出一次换行一次

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int main() {
    	string s = "I Love GPLT";
    	for(char & c : s) {
    		putchar(c);
    		putchar('
    ');	
    	}
    	return 0;
    }
    

    L1-027

    思路:

    映射一下即可

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int cnt[15], pos[15];
    void out(vector<int> & v){ cout << v[0]; for(int i = 1; i < v.size(); ++i) putchar(','), cout << v[i]; cout << "};
    "; }
    
    int main() {
    	string s;
    	cin >> s;
    	for(char & c : s) ++cnt[c- '0'];
    	vector<int> rcd, pos(15), tel;
    	for(int i = 10; i >= 0; --i) if(cnt[i]) pos[i] = rcd.size(), rcd.push_back(i);
    	cout << "int[] arr = new int[]{";
    	out(rcd);
    	for(char & c : s) tel.push_back(pos[c - '0']);
    	cout << "int[] index = new int[]{";
    	out(tel);
    	return 0;
    }
    

    L1-028

    思路:

    学会O(n)O(sqrt{n})复杂度判断素数

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    bool isPrime(int n){
    	int sq = sqrt(n);
    	for(int i = 2; i <= sq; i++){
    		if(n % i == 0) return false;
    	}
    	return n != 1;
    }
    
    int main() {
    	int kase, n;
    	cin >> kase;
    	while(kase--){
    		cin >> n;
    		puts(isPrime(n) ? "Yes" : "No");	
    	}
    	return 0;
    }
    

    L1-029

    思路:

    照意思计算即可

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int main() {
    	double h;
    	cin >> h;
    	printf("%.1f", (h - 100) * 1.8);
    	return 0;
    }
    

    L1-030

    思路:

    从排名高到底输出,需要配合排名最低的男生/女生;维护一下男生女生当前最低的是谁就行;

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    typedef pair<string, int> P;
    #define pb(x) push_back(x) 
    
    int main() {
    	int n;
    	cin >> n;
    	vector<string> boy, girl;
    	vector<pair<string, int> > tot; 
    	for(int i = 0; i < n; i++){
    		int x;
    		string s;
    		cin >> x >> s;
    		if(x) boy.pb(s); else girl.pb(s);
    		tot.pb(P(s, x));	
    	}
    	int x = n / 2, y = x;  //boy girl
    	map<string, bool> vst;
    	for(P & p : tot){
    		string now = p.first;
    		if(vst[now]) continue;
    		if(p.second){
    			cout << now << ' ' << girl[--y] << '
    ';
    			vst[girl[y]] = true;
    		}else{
    			cout << now << ' ' << boy[--x] << '
    ';
    			vst[boy[x]] = true;
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    【奇妙dp】ARC107D Number of Multisets
    【最短路-拆点】ARC061Cすぬけ君の地下鉄旅行/Snuke's Subway Trip
    【数学-思维-枚举方式】ARC060B 桁和/Digit Sum
    ARC107C Shuffle Permutation【有脑就行qwq/完全不知道怎么分类嘛】
    【kmp-循环节】ARC060D 最良表現/Best Representation
    【简单dp】ARC059C キャンディーとN人の子供 / Children and Candies
    【状压】ARC058E 和風いろはちゃん / Iroha and Haiku
    快速乘
    Miller Rabin素数测试和Pollard Rho算法
    JAVA补充-接口
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308685.html
Copyright © 2020-2023  润新知