The German Collegiate Programming Contest 2017
B - Building
给一个m各面的多边形柱体,每一侧面有n*n个格子,现在对这些格子染色,看有多少种方式使得多面柱体无论如何旋转都不会与另一个一样。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll n,m,c;
ll quickly_pow(ll x,ll y){
ll ans=;
while(y){
if(y&) ans=ans*x%mod;
y>>=;
x=x*x%mod;
}
return ans%mod;
}
int main(){
scanf("%lld%lld%lld",&n,&m,&c);
ll pos=quickly_pow(c,n*n);
ll ans=;
for(ll i=;i<=m;i++){
ans+=quickly_pow(pos,__gcd(i,m));
ans%=mod;
}
printf("%lld\n",ans*quickly_pow(m,mod-)%mod);
return ;
}
C - Joyride
有m条边n个点,经过每个点耗时t,花费p,经过每一条边花费ti,现在问你总共时间x,确保花完,在回到出口,花费最小。
bfs+剪枝
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
vector<int>v[];
vector<pair<int,int> >cost();
struct node{
int u,t,w;
node(int u,int t,int w):u(u),t(t),w(w){}
bool operator<(const node &a) const{
return w>a.w;
}
};
int x,n,m,t;
int dis[][];
void bfs(){
memset(dis,INF,sizeof(dis));
if(x-cost[].first<) return ;
priority_queue<node>q;
dis[][x-cost[].first]=cost[].second;
q.push(node(,x-cost[].first,cost[].second));
while(!q.empty()){
node e=q.top();
q.pop();
if(e.w>dis[e.u][e.t]) continue;
if(e.t-cost[e.u].first>=){
if(dis[e.u][e.t-cost[e.u].first]>(dis[e.u][e.t]+cost[e.u].second)){
dis[e.u][e.t-cost[e.u].first]=dis[e.u][e.t]+cost[e.u].second;
q.push(node(e.u,e.t-cost[e.u].first,dis[e.u][e.t-cost[e.u].first]));
}
}
for(int i=;i<v[e.u].size();i++){
if(e.t-t-cost[v[e.u][i]].first>=){
if(dis[v[e.u][i]][e.t-cost[v[e.u][i]].first-t]>(dis[e.u][e.t]+cost[v[e.u][i]].second)){
dis[v[e.u][i]][e.t-cost[v[e.u][i]].first-t]=dis[e.u][e.t]+cost[v[e.u][i]].second;
q.push(node(v[e.u][i],e.t-cost[v[e.u][i]].first-t,dis[v[e.u][i]][e.t-cost[v[e.u][i]].first-t]));
}
}
}
}
}
int main(){
scanf("%d%d%d%d",&x,&n,&m,&t);
for(int i=;i<m;i++){
int u,to;
scanf("%d%d",&u,&to);
v[u].push_back(to);
v[to].push_back(u);
}
for(int i=;i<=n;i++)
scanf("%d%d",&cost[i].first,&cost[i].second);
bfs();
if(dis[][]==INF) printf("It is a trap.\n");
else printf("%d\n",dis[][]);
return ;
}
D - Pants On Fire
根据前面n条句子,判断后面句子是否正确,传递性。
离散化+flyod
#include <bits/stdc++.h>
using namespace std;
map<string,int>m;
int n,q,ans=;
int vis[][];
string u,v,s;
int main(){
scanf("%d%d",&n,&q);
for(int i=;i<n;i++){
cin>>u>>s>>s>>s>>v;
vis[m[u]?m[u]:(m[u]=++ans)][m[v]?m[v]:(m[v]=++ans)]=;
}
for(int k=;k<=ans;k++)
for(int i=;i<=ans;i++)
for(int j=;j<=ans;j++)
if(vis[i][k] && vis[k][j]) vis[i][j]=;
while(q--){
cin>>u>>s>>s>>s>>v;
if(vis[m[u]][m[v]]) printf("Fact\n");
else if(vis[m[v]][m[u]]) printf("Alternative Fact\n");
else printf("Pants on Fire\n");
}
return ;
}
G - Water Testing
皮克定理,求多边形内部点的数量
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point{
ll x,y;
}p[];
ll n;
ll operator * (Point a,Point b){return a.x*b.y-a.y*b.x;}
ll cal(Point a,Point b){
if(a.x==b.x) return abs(b.y-a.y)-;
if(a.y==b.y) return abs(b.x-a.x)-;
return __gcd(abs(b.y-a.y),abs(a.x-b.x))-;
}
ll area(){
ll s=;
for(int i=;i<n;i++)
s+=p[i]*p[(i+)%n];
return abs(s);
}
ll solve(){
ll ans=n;
for(int i=;i<n;i++)
ans+=cal(p[i],p[(i+)%n]);
return ans-;
}
int main(){
scanf("%lld",&n);
for(int i=;i<n;i++)
scanf("%lld%lld",&p[i].x,&p[i].y);
printf("%lld\n",(area()-solve())/);
return ;
}
I - Uberwatch
K - You Are Fired!
在开除不超过k个人的情况下,使得工资大于等于d
优先队列
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int AX = 1e4 + ;
struct Node{
string s ;
ll v ;
bool operator < (const Node &ch )const{
return v < ch.v ;
}
}a[AX];
int main(){
ll n,d,k;
priority_queue<Node>q;
scanf("%lld%lld%lld",&n,&d,&k);
for(int i=;i<n;i++){
string s;
ll c;
cin>>s>>c;
q.push((Node){s,c});
}
int ans=;
while(!q.empty() && d> && ans<k){
Node e=q.top();
q.pop();
a[ans++]=e;
//printf("%lld\n",e.v);
d-=e.v;
}
if(d>) printf("impossible\n");
else{
printf("%d\n",ans);
for(int i=;i<ans;i++){
cout<<a[i].s<<",";
cout<<" YOU ARE FIRED!"<<endl;
}
}
return ;
}
The German Collegiate Programming Contest 2017的更多相关文章
- (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)
layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...
- 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)(9/11)
$$2017-2018\ ACM-ICPC\ German\ Collegiate\ Programming\ Contest (GCPC 2017)$$ \(A.Drawing\ Borders\) ...
- 2018 German Collegiate Programming Contest (GCPC 18)
2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...
- (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)
layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...
- German Collegiate Programming Contest 2018 C. Coolest Ski Route
John loves winter. Every skiing season he goes heli-skiing with his friends. To do so, they rent a h ...
- German Collegiate Programming Contest 2015 计蒜课
// Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...
- German Collegiate Programming Contest 2018 B. Battle Royale
Battle Royale games are the current trend in video games and Gamers Concealed Punching Circles (GCPC ...
- ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2017)- K. Poor Ramzi -dp+记忆化搜索
ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2017)- K. ...
- 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)
$$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...
随机推荐
- PhotoZoom官方这举动,大写服!
上上周,PhotoZoom Classic7首次特惠活动大家都知道哈~~ 厂商福利限量30套,仅售99RMB,活动一经上线,半天时间一售而光,这说明不是大家不需要这个智能小软件啊,而是,可能,大概,也 ...
- 面试题-mysql
Sql :UPDATE test SET sex = CASE sex WHEN 'm' THEN 'f' ELSE 'm' END;
- javaee字节流文件复制
package Zy; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.Fil ...
- JS 20180416考试
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Protocol Buffer格式传输
1.简单明了介绍ProtocolBuffer 2. ProtocolBuffer(pb)所做事情其实类似于xml.json,也就是把某种数据结构的信息依照某种格式保存起来.主要用于数据存储.传输等. ...
- class一些内置方法
一. __getattribute__ class Foo: def __init__(self,x): self.x=x def __getattr__(self, item): print('执行 ...
- IOS:兼容ios6和低版本
viewDidUnload在ios6开始被弃用了,所以我们在这里处理内存警告的这类问题,这个时候我们就要把相应的处理放在 didReceiveMemoryWarning中. - (void)didRe ...
- eclipse迅速新建main函数
创建类的时候勾选 或者在类的下面敲main,然后alt+/ 就可以了
- 【hiho一下 第三周】KMP算法
[题目链接]:http://hihocoder.com/problemset/problem/1015 [题意] [题解] 把f数组,len1,len2数组一开始全都定义成char型 这酸爽. [Nu ...
- 【hdu 4135】Co-prime
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=4135 [题意] 让你求出[a..b]这个区间内和N互质的数的个数; [题解] 利用前缀和,求出[1 ...