0%

日常刷題

有空再更新

m370

code AC(3ms, 352KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int x,n,a,l=0,r=0,mn=105,mx=-105;
cin>>x>>n;
for(int i=0;i<n;i++){
cin>>a;
if(a>x) r++,mx=max(mx,a);
else l++,mn=min(mn,a);
}
(l>r)?cout<<l<<" "<<mn:cout<<r<<" "<<mx;;
}

m931

code AC(2ms, 364KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,mx=0,tmp=0;
vector<vector<int>> v;
cin>>n;
v.resize(3,vector<int>(n));

for(int i=0;i<n;i++){
cin>>v[0][i]>>v[1][i];
v[2][i]=(v[0][i])*(v[0][i])+(v[1][i])*(v[1][i]);
if(v[2][i]>mx) mx=v[2][i],tmp=i;
}

v[2][tmp]=0,mx=0,tmp=0;

for(int i=0;i<n;i++){
if(v[2][i]>mx) mx=v[2][i],tmp=i;
}
cout<<v[0][tmp]<<" "<<v[1][tmp];
}

m932

code AC(2ms, 368KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0); //IO優化
vector<vector<char>> v;
bool t[123]={0}; //統計用陣列 (輸出第二行時用的到)
int m,n,k,d; //m,n,k為題目敘述 d代表的是input最後一行的整數
string s;
cin>>m>>n>>k;
int nowx=m-1,nowy=0,cnt=0; //nowx,nowy記錄現在位置的x和y cnt記錄種類
v.resize(m,vector<char>(n)); //動態開記憶體
for(int i=0;i<m;i++){ //把string丟進char陣列裡
cin>>s;
for(int j=0;j<n;j++){
v[i][j]=s[j];
}
}

for(int i=0;i<k;i++){ //先判斷現在往哪個方向 再判斷if(沒超過邊界)就更新現在位置;
cin>>d;
if(d==0){
if((nowx-1)>=0) nowx--;
}
else if(d==1){
if((nowy+1)<n) nowy++;
}
else if(d==2){
if((nowx+1)<m&&(nowy+1)<n) nowx++,nowy++;
}
else if(d==3){
if((nowx+1)<m) nowx++;
}
else if(d==4){
if((nowy-1)>=0) nowy--;
}
else if(d==5){
if((nowx-1)>=0&&(nowy-1)>=0) nowx--,nowy--;
}
cout<<v[nowx][nowy];
t[(int)(v[nowx][nowy])]=1; //這邊使用ASCII 轉成int 丟到陣列
}

for(int i='A';i<='Z';i++){ //跑陣列 統計多少種類
if(t[i]==1) cnt++;
}
for(int i='a';i<='z';i++){
if(t[i]==1) cnt++;
}
cout<<"\n"<<cnt;
}

網頁計數器