L1 语法+模拟
L2-1 stl
L2-2 stl
L2-3 bfs
L1-8 模拟太恶心没写
比赛和期末考撞个满怀太累了,计组要寄了(悲…
目录
L1-1 PTA使我精神焕发
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int main() {
cout<<"PTA shi3 wo3 jing1 shen2 huan4 fa1 !";
return 0;
}
L1-2 6翻了
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
string s;
int main() {
getline(cin,s);
int k=0;
for(int i=0;i<s.size();i++){
if(s[i]=='6') k++;
else {
if(k<=3) {
for(int j=1;j<=k;j++) cout<<"6";
}else if(k>3&&k<=9){
cout<<"9";
}else {
cout<<"27";
}
k=0;
cout<<s[i];
}
}
if(k){
if(k<=3) {
for(int j=1;j<=k;j++) cout<<"6";
}else if(k>3&&k<=9){
cout<<"9";
}else {
cout<<"27";
}
}
return 0;
}
L1-3 敲笨钟
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int n;
string s;
int main() {
cin>>n;
getchar();
for(int i=1;i<=n;i++){
getline(cin,s);
int f1=0,f2=0,k=0;
for(int j=0;j<s.size();j++){
if(s[j]==' '&&f2!=1) k++;
if(s[j]=='o'&&s[j+1]=='n'&&s[j+2]=='g'&&s[j+3]==',') f1=1;
if(s[j]=='o'&&s[j+1]=='n'&&s[j+2]=='g'&&s[j+3]=='.') f2=1;
}
if(f1==1&&f2==1){
k-=2;
int cnt=0;
while(k){
cout<<s[cnt];
if(s[cnt]==' ') k--;
cnt++;
}
cout<<"qiao ben zhong.";
} else{
cout<<"Skipped";
}
cout<<endl;
}
return 0;
}
L1-4 心理阴影面积
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int x,y;
int main() {
cin>>x>>y;
cout<<100*100/2-x*y/2-(y+100)*(100-x)/2;
return 0;
}
L1-5 新胖子公式
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
double w,h;
int main() {
cin>>w>>h;
double ans=w/(h*h);
printf("%.1lf\n",ans);
if(ans>25) {
printf("PANG");
}else{
printf("Hai Xing\n");
}
return 0;
}
L1-6 幸运彩票
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int n;
string x;
int main() {
cin>>n;
while(n--){
cin>>x;
int ans1=x[0]-'0'+x[1]-'0'+x[2]-'0';
int ans2=x[3]-'0'+x[4]-'0'+x[5]-'0';
if(ans1==ans2) {
cout<<"You are lucky!"<<endl;
}else{
cout<<"Wish you good luck."<<endl;
}
}
return 0;
}
L1-7 吃鱼还是吃肉
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e5+10,mod=1e9+7;
void solve(){
int id,h,w;
cin>>id>>h>>w;
if(id==1){
if(h<130) cout<<"duo chi yu! ";
if(h==130) cout<<"wan mei! ";
if(h>130)cout<<"ni li hai! ";
if(w<27) cout<<"duo chi rou!";
if(w==27) cout<<"wan mei!";
if(w>27) cout<<"shao chi rou!";
}else{
if(h<129) cout<<"duo chi yu! ";
if(h==129 ) cout<<"wan mei! ";
if(h>129) cout<<"ni li hai! ";
if(w<25) cout<<"duo chi rou!";
if(w==25) cout<<"wan mei!";
if(w>25) cout<<"shao chi rou!";
}
cout<<endl;
}
int main(){
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
L2-1 特立独行的幸福
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int a,b,vis[N];
vector<int>q;
map<int,int>mp;
int is_prime(int x){
if(x==1) return 1;
if(x==2||x==3) return 2;
for(int i=2;i<=x/i;i++){
if(x%i==0) return 1;
}
return 2;
}
int main() {
cin>>a>>b;
for(int i=a;i<=b;i++){
int k=i;
while(k!=1){
int sum=0;
while(k){
sum+=(k%10)*(k%10);
k/=10;
}
k=sum;
if(find(q.begin(),q.end(),sum)!=q.end()) break;
q.push_back(sum);
vis[sum]=1;
}
if(k==1) mp[i]=q.size();
q.clear();
}
if(!mp.size()){
cout<<"SAD"<<endl;
return 0;
}
for(auto i:mp){
if(!vis[i.first]){
cout<<i.first<<" "<<is_prime(i.first)*i.second<<endl;
}
}
return 0;
}
L2-2 冰岛人
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,string> PII;
int N, M;
string fName, sName, temp;
map<string, PII> mp;
string check(string a, string b) {
int cnt1 = 0, cnt2;
while (a != "") {
cnt2 = 0;
string b2 = b;
while (b2 != "") {
if (a == b2 && (cnt1 < 4 || cnt2 < 4)) return "No\n";
if (cnt1 >= 4 && cnt2 >= 4) return "Yes\n";
b2 = mp[b2].second;
cnt2++;
}
a = mp[a].second;
cnt1++;
}
return "Yes\n";
}
int main() {
cin >> N;
while(N--){
cin >> fName >> sName;
if (sName.back() == 'n') mp[fName] = {1, sName.substr(0, sName.length() - 4)};
else if (sName.back() == 'r') mp[fName] = {0, sName.substr(0, sName.length() - 7)};
else if (sName.back() == 'm') mp[fName].first = 1;
else mp[fName].first = 0;
}
cin >> M;
while(M--){
cin >> fName >> temp >> sName >> temp;
if (!mp.count(fName) || !mp.count(sName)) cout << "NA\n";
else if(mp[fName].first == mp[sName].first) cout << "Whatever\n";
else cout << check(fName, sName);
}
return 0;
}
L2-3 深入虎穴
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int n,k,x,vis[N];
vector<int>e[N];
int main() {
cin>>n;
for(int i=1;i<=n;i++){
cin>>k;
for(int j=1;j<=k;j++){
cin>>x;
e[i].push_back(x);
e[x].push_back(i);
}
}
queue<int>q;
q.push(1);
vis[1]=1;
while(!q.empty()){
x=q.front();
q.pop();
for(auto i:e[x]){
if(vis[i]) continue;
vis[i]=1;
q.push(i);
}
}
cout<<x<<endl;
return 0;
}