2020多校补题第四场

1011:
瞎算一通过了
看题解发现竟然直接输出就行
当时的代码:

#include<bits/stdc++.h>
using namespace std;
const double G=6.67430*1e-11;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
	    double a,b,d,t0;
		cin>>a>>b>>d>>t0;
		double cs=d;
		double s1=0.0;
		double s2=0.0;
		double s=0.0;
		t0=t0*t0;
		d=d*d*d*d*d*d;
		s1=a*G*t0/13000/d;
		s2=b*G*t0/13000/d;
		s=s1+s2;
		cs-=s;
		printf("%.20lf\n",cs);
	}
}

优秀的代码:

#include<bits/stdc++.h>
using namespace std;

int main(void) {
  int T;
  cin>>T;
  while (T--) {
    int d;
    scanf("%*d%*d%d%*d", &d);
   cout<<d;
  }
  return 0;
}

稽不如人,肝败吓疯

1002:
直接算时间就好,把最小的时间拿去比较,等于的胜率+(1)/n/2,时间少的加胜率1/n,累计出胜率

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		double a[1003]={0.0};
		double d[1003]={0.0};
		double c[1003]={0.0};
		double e[1003]={0.0};
		double zs=10000000.0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i]>>d[i];
			c[i]=a[i]/d[i];
			e[i]=100.0/a[i]*d[i];
		}
		sort(e+1,e+n+1);
		zs=e[1];
		double z=0.0;
		double x=1.0/n;
		int L=0;
		for(int i=1;i<=n;i++)
		{
			/*if(zs<e[i])
			z+=x;*/
			if(zs==e[i])
			//z=z+(x/2.0);
			L+=1;
		 } 
		 z=1.0-(L/n*0.5);
		 cout<<z<<endl;
	}
	return 0;
}

1004:
应该是有条件的最短路
用迪杰斯特拉算法:
首先把起点到所有点的距离存下来找个最短的,然后松弛一次再找出最短的,所谓的松弛操作就是,遍历一遍看通过刚刚找到的距离最短的点作为中转站会不会更近,如果更近了就更新距离,这样把所有的点找遍之后就存下了起点到其他所有点的最短距离
std code:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int maxv = maxn * 2 + 2;
typedef long long li;
typedef pair<int, int> pii;
const li infl = ~0LLU >> 2;
int n, m, s, t, cost_change;
char type[maxn + 1];
vector<pii> g[maxv];
int nv, S, T;
li dist[maxv];
struct Node {
  int u;
  li d;
  bool operator < (const Node &b) const {
    return d > b.d;
  }
};
priority_queue<Node> que;
li Dijkstra(void) {
  fill(dist, dist + nv, infl);
  dist[S] = 0;
  que.push({S, 0});
  while (!que.empty()) {
    int u = que.top().u;
    li d = que.top().d;
    que.pop();
    if (d != dist[u]) continue;
    for (pii e : g[u]) {
      int v = e.first, len = e.second;
      if (dist[u] + len < dist[v]) {
        dist[v] = dist[u] + len;
        que.push({v, dist[v]});
      }
    }
  }
  return dist[T];
}

inline bool Conflict(int t, char c) {
  return (t == 0 && c == 'R') || (t == 1 && c == 'L');
}

inline void AddEdge(int u, int v, int len) {
  g[u].push_back({v, len});
  g[v].push_back({u, len});
}

void Solve(void) {
  scanf("%d%d%d%d%d", &n, &m, &s, &t, &cost_change);
  --s; --t;
  scanf("%s", type);

  nv = n * 2 + 2;
  for (int i = 0; i < nv; ++i) {
    g[i].clear();
  }

  for (int i = 0; i < m; ++i) {
    int a, b, d;
    scanf("%d%d%d", &a, &b, &d);
    --a; --b;
    for (int ta = 0; ta <= 1; ++ta) {
      if (Conflict(ta, type[a])) continue;
      for (int tb = 0; tb <= 1; ++tb) {
        if (Conflict(tb, type[b])) continue;
        AddEdge(a << 1 | ta, b << 1 | tb, d + (ta != tb) * cost_change);
      }
    }
  }

  S = n * 2, T = S + 1;
  for (int ts = 0; ts <= 1; ++ts) {
    if (Conflict(ts, type[s])) continue;
    AddEdge(S, s << 1 | ts, 0);
  }
  for (int tt = 0; tt <= 1; ++tt) {
    if (Conflict(tt, type[t])) continue;
    AddEdge(T, t << 1 | tt, 0);
  }

  li ans = Dijkstra();
  printf("%lld\n", ans);
}

int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    Solve();
  }
  return 0;
}

只能勉强看懂,要自己写估计够呛。。

1005:
就是交换看种数
只要附近不相等,就能换
用一个数组统计当前种数,然后逐渐加和
数组要预处理

#include<bits/stdc++.h>
using namespace std;
const int N = 100001, mod = 1e9 + 7;
int f[N], n;
string s[N];
int jc() {
    cin>>n;
    for (int i=1;i<=n;i ++) 
	{
        cin>>s[i];
    }
    fill(f,f+n+1,0);
    f[0]=1;
    for (int i=1;i<=n;i ++) 
	{
        f[i]=f[i-1];
        if (i>=2&&s[i]!=s[i-1]) 
		{
            f[i]=(f[i]+f[i-2])%mod;
        }
    }
    return f[n];
}
int main() {
    int T;
    cin>>T;
    for (int i=1;i<=T;i++) 
	{
        cout<<jc()<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值