ACM-ICPC Shenyang Oniste 2018

C Insertion Sort

想了半年没想出来,看看巨佬的的吧
注:
突然发现自己想法大致是对来


#include <bits/stdc++.h>

using namespace std;

#define ll long long


void solve(int t) 
{
	ll n,k,q;scanf("%lld%lld%lld",&n,&k,&q);
    // k = min (n,k);
	if (k >= n) {
		ll ans = 1;
		for (ll i = 1;i <= n;i ++) {
			ans = ans * i % q;
		}
		printf("Case #%d: %lld\n",t,ans);
	} else {
		ll ans = 1;
		for (ll i = 1;i <= k;i ++) {
			ans = ans * i % q;
		}  
		ll jiecheng = ans;
        ans = ((n-k) *(k+1) + (n-k-1)*(n-k-1)) * jiecheng %q;
		// ans =(ans + (k * (n-k) + (n-k) * (n-k-1) / 2) * jiecheng% q) % q;
		// ans =(ans + jiecheng * (n-k)) % q;
        // ans = (ans-jiecheng+q)%q;
		printf("Case #%d: %lld\n",t,ans);
	}
}

int main()
{

	ll ans = 0;
	int t;scanf("%d",&t);
	for(int i= 1;i <= t;i ++) {
		solve(i);
	}
}
  • 思路

1.全排列 —— k ! k! k!
2.剩下的那个元素出现在了 n − k n-k nk
那么就是 ( ( n − k ) ∗ k + ( n − k − 1 ) ( n − k ) ) ∗ k ! ((n-k)*k+(n-k-1)(n-k))*k! ((nk)k+(nk1)(nk))k!
分两部分, 1 − k 1-k 1k出现在了后面, n − k n-k nk 后面有其中一个数出现逆序的问题(就是这里想岔了,每一个数都可以有 n − k n-k nk 个位置,不用除以2。哎哎哎,一晚上又没了。。。回去写计组了。。。
3.剩下的那个元素出现了 1 − k 1-k 1k
那么就是 ( n − k ) ∗ k ! (n-k)*k! (nk)k!
但是这样算的话,相邻的会有一个重复的,就是 k 和 k + 1 k和k+1 kk+1 ,所以上述三种情况加起来后在减去一个 k ! k! k!

签到题

不写了

#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int N = 1e7;
// const ll MAX = 5010*5010*5010;
ll count_byte(string s) 
{
	if (s[0] == 'b'||s[0] == 'c') return 1;//bool char
	if (s[0] == 'f'||s[0] == 'i') return 4;//int float
	if (s[0] == '_') return 16; //__int128
	if (s[0] == 'd') return 8; // double 
	if (s[8] == 'g') return 8; //long long
	return 16; //long double
}

void solve(int t) 
{
	int n;cin>>n;
	string s;cin.ignore();
	ll ans = 0;
	while(n --) {
		getline(cin,s);
        // cout<<s<<endl;
		if (s.find("[") != s.npos) {
			ll cnt = 0;
			int i;
			for (i = 0;i < s.size();i ++) {
				if (s[i] == '[') break;
			}
			for (int j = i + 1;j < s.size();j ++) {
				if (s[j] == ']') break;
				else {
					cnt = cnt * 10 + s[j] - '0';
				}
			}
            // cout<<"cnt"<<cnt<<endl;
			ans += cnt * count_byte(s);
		} else {
			ans += count_byte(s);
		}
	}
    if (ans % 1024 == 0) {
        ans /=1024;
    } else {
        ans = ans / 1024 + 1;
    }
	printf("Case #%d: %lld\n",t,ans);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif 
	int t;cin>>t;
	for(int i= 1;i <= t;i ++) {
		solve(i);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯狂的码泰君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值