不解釋
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin>>n>>m;
cout<<n*m<<"\n";
}
基礎 for 迴圈,提醒小小的點,當天 js 有上班才可以給錢
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,ret=0;
cin>>n;
for(int i=0;i<n;++i){
int ct=0;
bool tp,js;
cin>>tp;
ct+=tp;
cin>>js;
ct+=js;
cin>>tp;
ct+=tp;
if(js){
ret+=4500/ct;
}
}
cout<<ret<<"\n";
}
高速( 複雜度
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
using ll=long long;
ll POW(ll a,ll x){
ll ret=1;
while(x>0){
if(x&1) ret=ret*a%MOD;
a=a*a%MOD;
x>>=1;
}
return ret;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin>>n;
cout<<(ll)54*POW(2,n)%MOD<<"\n";
}
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,k;
cin>>n>>k;
int val=0,day;
for(int i=0;i<n;++i){
int ct=0;
int tp;
while(cin>>tp && tp!=0){
ct++;
}
val+=ct*ct;
if(val>=k){
day=i;
break;
}
}
cout<<day<<"\n";
}
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,t;
cin>>n>>t;
vector<vector<int>> dp(2,vector<int>(n+1));
int tp=0;
for(int i=1;i<=n;++i){
int ai;
cin>>ai;
if(tp<=t){
dp[0][i]=max(dp[0][i-1],dp[1][i-1])+ai;
}else{
dp[0][i]=dp[1][i-1]+ai;
}
dp[1][i]=max(dp[0][i-1],dp[1][i-1]);
tp=ai;
}
cout<<max(dp[1][n],dp[0][n])<<"\n";
}
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,q;
cin>>n>>q;
vector<int> qq(q);
for(int i=0;i<q;++i){
cin>>qq[i];
}
vector<string> voc(n+1);
for(int i=1;i<=n;++i){
cin>>voc[i];
}
for(int i=0;i<q;++i){
cout<<voc[qq[i]]<<"\n";
}
}
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
using ll=long long;
using pll=pair<ll,ll>;
const int N=100010;
const ll INF=0x3f3f3f3f3f3f3f3f;
int n,m,cp;
ll dis[N];
vector<pll> g[N];
bool vis[N];
void solve(){
cin>>n>>m;
for(int i=1;i<=m;++i){
int a,b,c;
cin>>a>>b>>c;
g[a].emplace_back(c,b);
g[b].emplace_back(c,a);
}
fill(dis,dis+n+5,INF);
int s,t;
cin>>s>>t;
dis[s]=0;
priority_queue<pll,vector<pll>,greater<pll>> pq;
pq.emplace(0,s);
while(!pq.empty()){
pll now=pq.top();
pq.pop();
if(now.F>dis[now.S]) continue;
dis[now.S]=now.F;
for(auto e:g[now.S]){
pq.emplace(e.F+now.F,e.S);
}
}
cout<<dis[t];
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int t=1;
while(t--){
solve();
}
}
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,t;
cin>>n>>t; cin.ignore();
vector<string> dic(t);
for(int i=0;i<t;++i){
getline(cin,dic[i]);
}
for(int i=0;i<n;++i){
int r,c;
cin>>r>>c;
r--, c--;
cout<<dic[r][c];
}
}
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string str;
while(cin>>str){
for(int i=0;i<str.size();++i){
if(islower(str[i]) || isupper(str[i])){
cout<<int(str[i]-'a')+50*(str.size()-i-1)<<" ";
}
}
}
}
#include<bits/stdc++.h>
using namespace std;
struct pt{
int x,y,z;
pt(int a=0,int b=0,int c=0){
x=a; y=b; z=c;
}
};
int main(){
pt l1,l2,p1,p2;
cin>>p1.x>>p1.y>>p1.z;
cin>>l1.x>>l1.y>>l1.z;
cin>>p2.x>>p2.y>>p2.z;
cin>>l2.x>>l2.y>>l2.z;
int d = l1.x*l2.y - l1.y*l2.x;
int dx= (p2.x - p1.x)*l2.y - (p2.y - p1.y)*l2.x;
int dy= l1.x*(p2.x - p1.x) - l1.y*(p2.y - p1.y);
int t=dx/d,k=dy/d;
cout<<l1.x*t+p1.x<<" "<<l1.y*t+p1.y<<" "<<l1.z*t+p1.z<<"\n";
}
定義子問題。
Dec 20, 2024給定一個帶權圖G,求一條路徑讓S到T的權重總和最小。
Aug 9, 2023#include<bits/stdc++.h> using namespace std; unsigned seed=chrono::steady_clock().now().time_since_epoch().count(); mt19937_64 rng(seed); struct Treap{ struct node{ int key,val,pos,pri,sz; int mx,mxPos;
Jun 17, 2023題目敘述 神獸日京元帶著得意門生黃瓜學長去科博館,在館外有一個裝置,內有多個球不斷的被送進一個"單一"開口的管子,而過了一段時間後,系統會將管子傾斜並將部分的球送出。而現在正在舉辦一個活動,主辦單位將球編號(1,2,3...,n),而參加者要控制系統並將球經過操作後排成特定的順序,完成者能免費進入科博館。黃瓜學長作為一個資訊高手aka厭惡零錢大鈔主義者,又不想被坑錢,他必須完成目標。 輸入說明 第一行為一整數$n(0<n<10^5)$ 第二行有$n$個正數$a_1,a_2,....a_n(1 \le a_i \le n)$ 輸出說明 求第二行之排序有沒有可能達成,有的話輸出"Yes",否則輸出"No"
Jun 17, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up