视频题解戳这里!!!
由于视频题解的存在和时间原因,笔者就不写文字题解了。这里只放上代码供大家查阅。
A
#include
using namespace std;
#define ll long long
int t,n,k;
struct point
{
ll x,y;
} a[105];
int main()
{
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&k);
for (int i=1; i<=n; i++)
{
scanf("%lld%lld",&a[i].x,&a[i].y);
}
vector<ll> v;
for (int i=1; i<=n; i++)
{
for (int j=i+1; j<=n; j++)
{
for (int w=j+1; w<=n; w++)
{
ll area=abs((a[j].x-a[i].x)*(a[w].y-a[i].y)-(a[w].x-a[i].x)*(a[j].y-a[i].y));
v.push_back(area);
}
}
}
nth_element(v.begin(),v.begin()+n*(n-1)*(n-2)/6-k,v.end());
ll ans=v[n*(n-1)*(n-2)/6-k];
if (ans%2==0) printf("%lld.00\n",ans/2);
else printf("%lld.50\n",ans/2);
}
return 0;
}
B
#include
using namespace std;
const int maxp = 10;
const int maxn = 5e2+5;
map<string, int> name_ID;
struct people{
bool valid;
int score[maxp];
int penalty[maxp];
int final;
}peo[maxn];
const int scores[] = {0, 500, 1000, 1500, 2000, 2500};
int main() {
std::ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
string name;
for (int i = 1; i <= n; ++i) {
cin >> name;
name_ID[name] = i;
}
int t;
char prob;
string user, status;
while (m--) {
cin >> t >> user >> prob >> status;
int uid = name_ID[user];
int pid = prob-'A'+1;
peo[uid].valid = true;
if (status == "AC") {
peo[uid].penalty[pid]++;
peo[uid].score[pid] = max(scores[pid]/10*3, scores[pid]-scores[pid]/250*t-50*(peo[uid].penalty[pid]-1));
} else if (status == "CE") {
peo[uid].score[pid] = 0;
} else {
peo[uid].penalty[pid]++;
peo[uid].score[pid] = 0;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 5; ++j) {
peo[i].final += peo[i].score[j];
}
}
int cnt = 0;
int rk = 1;
for (int i = 1; i <= n; ++i) {
if (peo[i].valid)
cnt++;
if (peo[name_ID["cnz"]].final < peo[i].final) {
rk++;
}
}
if (peo[name_ID["cnz"]].valid) {
cout << peo[name_ID["cnz"]].final << endl;
cout << rk << "/" << cnt << endl;
} else {
cout << -1 << endl;
}
return 0;
}
C
#include
using namespace std;
int main()
{
long double n,ans;
scanf("%Lf",&n);
int i;
for(i=0;ans<n;i++)
{
ans = ans*3+1;
}
printf("%d\n",i);
return 0;
}
D
#include
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
int n,num=0,tp;
int main()
{
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>tp;
if(tp<60) num++;
}
cout<<num*400<<endl;
return 0;
}
E
#include
using namespace std;
const int maxn = 1e7+7;
int a[maxn];
int n,m;
int count(int x)
{
int ans = 0;
while(x)
{
if(x&1) ans++;
x>>=1;
}
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
if(m%2==0) printf("NO\n");
else
{
printf("YES\n");
a[0] = 0;
a[1] = 1;
for(int i=1;i<n;i++)
{
for(int j=(1<<i);j<1<<(i+1);j++)
{
a[j] = a[(1<<i+1)-j-1]+(1<<i);
}
}
if(m==1)
{
for(int i=0;i<1<<n;i++) printf("%d\n",a[i]);
}
else
{
for(int i=0;i<1<<m+1;i++)
{
if(i&1) a[i] ^= (1<<m+1)-1;
}
for(int i=m+1;i<n;i++)
{
int p = -1;
for(int j=0;j<1<<i;j++)
{
if(count(a[j]^a[(1<<i)-1])==m-1 && count(a[j ? (j-1) : ((1<<i)-1)])==m-1)
{
p = j;
break;
}
}
for(int j=0;j<1<<i;j++) a[j+(1<<i)] = a[(j+p)%(1<<i)]+(1<<i);
}
for(int i=0;i<1<<n;i++) printf("%d\n",a[i]);
}
}
return 0;
}
F
#include
using namespace std;
const int maxn = 5e5+7;
int n,m;
int dfn[maxn],low[maxn];
bool ins[maxn];
stack<int> s;
int col[maxn];
int cnt = 0;
int tot = 0;
int a[maxn];
vector<int> G[maxn];
vector<int> v[maxn];
void add_edge(int from,int to)
{
G[from].push_back(to);
}
void tarjan(int x)
{
low[x] = dfn[x] = ++cnt;
s.push(x);
ins[x] = 1;
for(int i=0;i<G[x].size();i++)
{
int v = G[x][i];
if(!dfn[v])
{
tarjan(v);
low[x] = min(low[x],low[v]);
}
else if(ins[v])
{
low[x] = min(low[x],dfn[v]);
}
}
if(low[x]==dfn[x])
{
tot++;
while(true)
{
int tmp = s.top();
s.pop();
col[tmp]=tot;
ins[tmp] = 0;
if(tmp==x) break;
}
}
}
bool check(int n)
{
for(int i=0;i<n;i++)
{
if(!dfn[i]) tarjan(i);
}
for(int i=0;i<n;i+=2)
{
if(col[i]==col[i^1]) return false;
}
return true;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=0;i<m;i++)
{
int x;
scanf("%d",&x);
for(int j=1;j<=x;j++)
{
int k;
scanf("%d",&k);
v[k].push_back(i);
}
}
for(int i=1;i<=n;i++)
{
if(v[i].size()==0)
{
if(a[i])
{
printf("NO\n");
return 0;
}
}
else if(v[i].size()==1)
{
if(a[i])
{
int x = v[i][0]<<1;
add_edge(x,x^1);
}
else
{
int x = v[i][0]<<1;
add_edge(x^1,x);
}
}
else if(v[i].size()==2)
{
if(a[i])
{
int x = v[i][0]<<1;
int y = v[i][1]<<1;
add_edge(x,y^1);
add_edge(x^1,y);
add_edge(y,x^1);
add_edge(y^1,x);
}
else
{
int x = v[i][0]<<1;
int y = v[i][1]<<1;
add_edge(x,y);
add_edge(x^1,y^1);
add_edge(y,x);
add_edge(y^1,x^1);
}
}
}
if(check(2*m)) printf("YES\n");
else printf("NO\n");
return 0;
}
G
#include
using namespace std;
string s,t;
bool flag = false;
void dfs(int a,int b,int cnt)
{
if(cnt>2) return;
if(a==s.size() && b==t.size())
{
flag = true;
return;
}
if(s[a]==t[b])
{
dfs(a+1,b+1,cnt);
}
else
{
dfs(a+1,b,cnt+1);
dfs(a,b+1,cnt+1);
dfs(a+1,b+1,cnt+1);
}
}
int main()
{
cin>>s>>t;
dfs(0,0,0);
if(flag) printf("YES\n");
else printf("NO\n");
return 0;
}
H
#include
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e5+7;
int isprime[maxn];
int prime[maxn];
int cnt = 0;
void getprime()
{
memset(isprime,INF,sizeof(isprime));
isprime[0] = isprime[1] = 0;
for(int i=2;i<maxn;i++)
{
if(isprime[i])
{
prime[++cnt] = i;
}
for(int j=1;j<=cnt && i*prime[j]<maxn;j++)
{
isprime[i*prime[j]] = 0;
if(i%prime[j]==0) break;
}
}
}
int main()
{
getprime();
for(int i=1;i<=2000;i++) printf("%lld\n",prime[i]*prime[4000-i]);
return 0;
}
I
#include
using namespace std;
const int maxn = 2e3+5;
const int maxp = 2e4+5;
int is_prime[maxp];
int prime[maxp];
int k = 0;
void getprime()
{
memset(is_prime, -1, sizeof(is_prime));
for (int i = 2; i < maxp; ++i)
{
if (is_prime[i])
{
prime[++k] = i;
}
for (int j = 1; j <= k && i*prime[j] < maxp; ++j)
{
is_prime[i*prime[j]] = 0;
if (i % prime[j] == 0) break;
}
}
}
unordered_map<int, int> G[maxn];
int main()
{
getprime();
int n;
cin >> n;
int tmp;
for (int i = 1; i <= n; ++i)
{
cin >> tmp;
for (int j = 1; j <= k; ++j)
{
if (tmp % prime[j] == 0)
{
int cnt = 0;
while (tmp % prime[j] == 0)
{
cnt++;
tmp /= prime[j];
}
if (cnt)
G[i][prime[j]] = cnt;
}
if (tmp == 1)
break;
}
if (tmp != 1)
G[i][tmp] = 1;
}
int ans = 0;
for (int i = 1; i < n; ++i)
{
if (G[i].size() >= 4)
continue;
for (int j = i+1; j <= n; ++j)
{
if (G[j].size() >= 4)
continue;
int res = 1;
for (auto pr1 : G[i])
{
int fac = pr1.first;
int cnt = pr1.second;
if (G[j].count(fac))
cnt += G[j][fac];
res *= (cnt+1);
}
for (auto pr2 : G[j])
{
int fac = pr2.first;
int cnt = pr2.second;
if (G[i].count(fac))
cnt = 0;
res *= (cnt+1);
}
if (res <= 10)
{
ans++;
}
}
}
cout << ans << endl;
return 0;
}
J
#include
using namespace std;
const int maxn = 1e5+7;
int n;
struct node
{
int a;
int b;
}Q[maxn];
bool cmp(node x,node y)
{
if(x.b==y.b) return x.a>y.a;
return x.b<y.b;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&Q[i].a);
}
for(int i=1;i<=n;i++)
{
scanf("%d",&Q[i].b);
}
sort(Q+1,Q+1+n,cmp);
int ans = 0;
int i;
for(i=1;i<=n;i++)
{
if(i==1) ans += Q[i].b;
else ans += Q[i].b-Q[i-1].b-2;
if(ans>=Q[i].a) ans -= Q[i].a;
else break;
}
if(i>n) printf("YES\n");
else printf("NO\n");
return 0;
}