首先是杭电多校第八场的某些题解
首先是1010题~~水题直接上代码~~
#include
using namespace std;
struct node{
string s;
int c,t;
}a[110000];
bool cmp(node x,node y){
if(x.c==y.c) return x.t<y.t;//罚时长的排后面
return x.c>y.c;//成绩高的排前面
}
int t,n,d;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>t;
while(t--){
cin>>n>>d;
for(int i=1;i<=n;i++) cin>>a[i].s>>a[i].c>>a[i].t;
if(n*d%10!=5){
cout<<"Quailty is very great"<<endl;
continue;
}
sort(a+1,a+1+n,cmp);
cout<<a[(n*d/10)+1].s<<endl;
}
return 0;
}
然后是稍微有点思维的1011题目
题目很奇妙
题目的意思很简单,关键是看思维
代码中有注释 嘤嘤嘤
#include
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
vector<long long>a;
vector<long long>b;
long long suma = 0, sumb = 0;
for (int i = 0; i < n; i++) {
long long a1, b1;
scanf("%lld %lld", &a1, &b1);
suma += a1;
sumb += b1;
a.push_back(a1);
b.push_back(b1);
}
long long ans = min(suma, sumb);
long long rest = 0;
//考虑将a1,a2设置为当前某个队伍的人数和剩余的人数
//b1,b2为当前某个队伍的奶茶数和剩余的奶茶数
//首先,如果人数大于奶茶数的情况下
if (suma > sumb) {
for (int i = 0; i < n; i++) {
if ((suma - a[i]) < b[i]) {
//如果剩余的人数小于当前的奶茶数,那么一定会有b[i] - suma + a[i]个奶茶会被浪费
//假设的前提是这些奶茶一定会全部被喝。
//如果上面情况成立,那么当前人数一定大于剩余奶茶数,往下进行
//另外,如果当前人数小于剩余奶茶数,那么剩余人数一定大于当前奶茶数。但是,考虑的只是针对当前来说,对于剩余并没有什么意义,不用计算。(因为一直要往下计算,不能重复计算)
rest += (b[i] - suma + a[i]);
}
}
}
//再其次,如果奶茶数大于人数
else {
for (int i = 0; i < n; i++) {
if ((sumb - b[i]) < a[i]) {
//如果剩余奶茶数小于当前人数,就当前人数来说,一定有a[i] - sumb + b[i]个人没喝上奶茶
rest += (a[i] - sumb + b[i]);
}
}
}
printf("%lld\n", ans - rest);
}
}
然后就是最后一个题目1009:
不大会然后直接DownLoad+copy 253的代码
希望之后能看懂吧 %%%%%
#include
using namespace std;
#define endl '\n'
typedef long long ll;
#define int long long
int x1, y_1, x2, y2, x3, y3, x4, y4;
bool check1()///完全重合
{
return x1 == x3 && y_1 == y3 && x2 == x4 && y2 == y4;
}
bool check2()///无公共区域
{
return x3 >= x2 || y3 >= y2 || y4 <= y_1;
}
bool check3()///完全包含
{
if ((x1 != x3 && x2 >= x4 && y2 >= y4 && y_1 <= y3) || (x1 == x3 && x4 >= x2 && y3 <= y_1 && y4 >= y2) || (x1 == x3 && x2 >= x4 && y_1 <= y3 && y2 >= y4))
{
if (x1 == x3 && x2 == x4 && y_1 != y3 && y2 != y4)return false;
if (y_1 == y3 && y2 == y4 && x1 != x3 && x2 != x4)return false;
return true;
}
else return false;
}
bool check4()///6个
{
return x1<x3 && x2>x4 && y_1 > y3 && y2 < y4;
}
bool check5()///5个
{
return (x1<x3 && x2 == x4 && y_1>y3 && y2 < y4) || (x1<x3 && x2>x4 && y_1 > y3 && y2 == y4) || (x1 == x3 && x2 < x4 && y_1<y3 && y2>y4) || (x1<x3 && x2>x4 && y_1 == y3 && y2 < y4);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--)
{
cin >> x1 >> y_1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
if (x3 < x1)///保证第二个左边界在第一个左边界右边
{
swap(x3, x1);
swap(y3, y_1);
swap(x4, x2);
swap(y4, y2);
}
else if (x3 == x1 && x2 > x4)
{
swap(x3, x1);
swap(y3, y_1);
swap(x4, x2);
swap(y4, y2);
}
if (check1())
{
cout << "2" << endl;
}
else if (check2() || check3())
{
cout << "3" << endl;
}
else if (check4())
{
cout << "6" << endl;
}
else if (check5())
{
cout << "5" << endl;
}
else
{
cout << "4" << endl;
}
}
return 0;
}
#include
using namespace std;
using ll long long;
map<ll,string>mp;
ll a[40];
ll n,m;
void dfs1(int cur,ll res,string path)//先是左半边搜索(类似于排列组合)
{
if(cur==n/2+1){
mp[res]=path;
return;
}
path+='1';
dfs1(cur+1,res+a[cur],path);
path[path.size()-1]='0';
dfs1(cur+1,res,path);
}
void dfs2(int cur,ll res,string path)//结合左半边,对比右半边
{
if(cur==n+1)
{
if(mp.find(m-res)!=mp.end())
{
for(auto xy:mp[m-res])//这个地方一定要注释一下
/*
意思是mp[m-res]是一个容器,冒号的意思是迭代容器中所有的元素,每一个元素的临时名字就是xy
*/
{
cout<<xy;
}
for(int i=0;i<path.size();i++)
{
cout<<path[i];
}
cout<<endl;
}
return;
}
path+='1';
dfs2(cur+1,res+a[cur],path);
path[path.size()-1]='0';
dfs2(cur+1,res,path);
}
int main() {
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
dfs1(1,0,"");
dfs2(n/2+1,0,"");
return 0;
}
//上代码!!
#include
using namespace std;
int mod = 1000000007;
map<int,int>ins;
#define __int128 unsigned long long
__int128 Csum;
__int128 ans;
#define N 100005
int belong[N];
int cur[N];
int Finds(int x){
return x==belong[x]?x:(belong[x] = Finds(belong[x]));
}
int Union(int a,int b,pair<int,int>&sb){
int pa = Finds(a);
int pb = Finds(b);
if(pa==pb){
return 0;
}else{
belong[pa] = pb;
sb = make_pair(cur[pb],cur[pa]);
cur[pb]+=cur[pa];
cur[pa] = 0;
return 1;
}
}
unsigned long long C(int a,int b){
__int128 res = 1,fac = 1;
if(a<b)return 0;
for(int i = 1 ; i <= b; ++i){
res*=a-i+1ll;
res/=i;
}
res/=fac;
return (unsigned long long)res;
}
int main(){
int T;
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n,m;
cin>>n>>m;
Csum = 0;
for(int i = 1 ; i <= n ; ++i){
belong[i] = i;
cur[i] = 1;
}
ans = C(n,4);
cout<<(unsigned long long)ans<<'\n';
int a,b;
int tot = n;
pair<int,int>to_s;
for(int j = 1 ; j <= m ; ++j){
cin>>a>>b;
if(tot<4){
cout<<0<<'\n';
}else if(Union(a,b,to_s)){
Csum-=C(to_s.first,2)+C(to_s.second,2);
ans-=to_s.first*to_s.second*(C(n-to_s.second-to_s.first,2)-Csum);
Csum+=C(to_s.second+to_s.first,2);
cout<<(unsigned long long)ans<<'\n';
--tot;
}else{
cout<<(unsigned long long)ans<<'\n';
}
}
}
持续学习ing
接下来的日子持续更新题目。
要开始刷题模式了