CSU 1427: Infected Computer 1433: Defend the Bases 1436: Revenge of the Round Table 1438: Swyper Key
阿新 • • 發佈:2019-02-09
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define max 20005
#define ll long long
using namespace std;
struct G{
int from;
int to;
ll time;
}game[max];
bool graf[max];
bool cmp(G a,G b){
return a.time < b.time;
}
int main()
{
int n,m;
while (cin>>n>>m){
for(int i = 0;i < max;i++){
graf[i]=false;
game[i].time=game[i].from=game[i].to=0;
}
graf[1]=true;
for(int i = 0;i < m;i++){
cin>>game[i].time>>game[i].from>>game[i].to;
}
sort(game,game+m,cmp);
bool flag = false;
for(int i = 0;i < m;i++){
if(game[i].from==1){
flag = true;
//graf[game[i].to] = true;
}
if(flag&&graf[game[i].from]){
graf[game[i].to] = true;
}
}
ll ans = 0 ;
for(int i = 1;i <= n;i++){
if(graf[i])ans++;
}
cout<<ans<<endl;
}
return 0;
}
/**********************************************************************
Problem: 1427
User: 3901140225
Language: C++
Result: AC
Time:48 ms
Memory:2356 kb
**********************************************************************/
#include <iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 110
using namespace std;
int n,m;
struct Troop
{
double x,y,v;
};
Troop a[maxn];
struct Base
{
double x,y;
};
Base b[maxn];
int head[maxn];
struct Edge
{
int to,next;
};
Edge e[10010];
int cnt_edge;
int vis[maxn];
int mat[maxn];
int match;
void init()
{
memset(head,-1,sizeof head);
memset(mat,0,sizeof mat);
cnt_edge = 0;
match = 0;
}
void add_edge(int a,int b)
{
e[cnt_edge].to = b;
e[cnt_edge].next = head[a];
head[a] = cnt_edge;
cnt_edge++;
}
bool crosspath(int k)
{
for(int i = head[k]; i !=-1; i = e[i].next)
{
int j = e[i].to;
if(!vis[j])
{
vis[j] = 1;
if(!mat[j] || crosspath(mat[j]))
{
mat[j] = k;
return true;
}
}
}
return false;
}
void hungary()
{
for(int i = 1; i <= n; i++)
{
memset(vis,0,sizeof vis);
if(crosspath(i))
{
match++;
}
}
}
double dis(int i,int j)
{
double temp = sqrt((a[i].x - b[j].x)*(a[i].x - b[j].x) + (a[i].y - b[j].y)*(a[i].y - b[j].y));
return temp/a[i].v;
}
int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
for(int i = 1; i <= n; i++)
{
scanf("%lf %lf %lf",&a[i].x,&a[i].y,&a[i].v);
}
for(int i = 1; i <= m; i++)
{
scanf("%lf %lf",&b[i].x,&b[i].y);
}
double low = 0;
double high = 15000;
double mid;
while(high - low > 0.000000001)
{
mid = (low + high)/2;
init();
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
if(dis(i,j) < mid)
{
add_edge(i,j);
}
}
hungary();
int flag = 1;
for(int i = 1; i <= m; i++)
{
if(!mat[i])
{
flag = 0;
break;
}
}
if(flag) high = mid;
else low = mid;
}
printf("%.10lf\n",mid);
}
return 0;
}
/**********************************************************************
Problem: 1433
User: 3901140225
Language: C++
Result: AC
Time:52 ms
Memory:2120 kb
**********************************************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1010;
const int mod = 1000003;
typedef long long LL;
int dpA[maxn][maxn],dpB[maxn][maxn],dp[maxn];
int n,k;
LL ans,all;
void DP(){
memset(dpA,0,sizeof(dpA));
memset(dpB,0,sizeof(dpB));
memset(dp,0,sizeof(dp));
int asum = 1,bsum = 0;
if(k >= n){
k = n-1;
all = 2;
}
dpA[1][1] = 1;
dpB[1][1] = 0;
for(int i = 2;i <= n;i++){
dpA[i][1] = bsum;
dpB[i][1] = asum;
swap(asum,bsum);
for(int j = 2;j <= min(n,k);j++){
dpA[i][j] = dpA[i-1][j-1];
asum = (asum+dpA[i][j])%mod;
dpB[i][j] = dpB[i-1][j-1];
bsum = (bsum+dpB[i][j])%mod;
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= min(n,k);j++){
dp[i] += dpB[i][j];
dp[i] %= mod;
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j < k;j++){
dpB[i][j+1] += dpB[i][j];
dpB[i][j+1] %= mod;
}
}
for(int i = 1;i <= n;i++){
for(int p = 1;p <= min(i,k);p++){
dp[i] += dpB[i-p][k-p];
dp[i] %= mod;
}
}
}
int gcd(int a,int b){
return b == 0 ? a : gcd(b,a%b);
}
LL pow_mod(LL a,LL n){
LL ret = 1;
while(n){
if(n&1) ret = ret*a%mod;
n >>= 1;
a = a*a%mod;
}
return ret;
}
int main()
{
while(scanf("%d%d",&n,&k) == 2){
ans = 0,all = 0;
DP();
for(int i = 0;i < n;i++){
ans += 2*dp[gcd(i,n)];
ans %= mod;
}
ans = ans*pow_mod(n,mod-2)%mod;
printf("%lld\n",(ans+all)%mod);
}
return 0;
}
/**********************************************************************
Problem: 1436
User: 3901140225
Language: C++
Result: AC
Time:44 ms
Memory:9996 kb
**********************************************************************/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <assert.h>
#include <algorithm>
#define MAX 1234567890
#define MIN -1234567890
#define eps 1e-8
using namespace std;
int cnt;
char key[104];
char road[20004];
/// * A B C D E * 00 01 02 03 04 05 06 ** 00 01 02 03 04 **
/// F G H I J K L 07 08 09 10 11 12 13 05 06 07 08 09 10 11
/// M N O P Q R S 14 15 16 17 18 19 20 12 13 14 15 16 17 18
/// T U V W X Y Z 21 22 23 24 25 26 27 19 20 21 22 23 24 25
int P[28][2] = {
{2, 8}, {4, 8}, {6, 8}, {8, 8}, {10, 8}, {12, 8}, {14, 8},
{2, 6}, {4, 6}, {6, 6}, {8, 6}, {10, 6}, {12, 6}, {14, 6},
{2, 4}, {4, 4}, {6, 4}, {8, 4}, {10, 4}, {12, 4}, {14, 4},
{2, 2}, {4, 2}, {6, 2}, {8, 2}, {10, 2}, {12, 2}, {14, 2},
};
int pos[26] = {
1, 2, 3, 4, 5,
7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27,
};
int ret[28] = {
0, 0, 1, 2, 3, 4, 0,
5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25,
};
int judge(int x1, int y1, int x2, int y2)
{
return x1*y2 - x2*y1;
}
///給定起點位置和終點位置
void findroad(int first, int last)
{
int dx = P[last][0] > P[first][0] ? 1 : -1;
int dy = P[last][1] > P[first][1] ? 1 : -1;
if(P[last][0] == P[first][0])
{
if(dy > 0) for(int i = first-7; i >= last; i -= 7) road[cnt++] = 'A' + ret[i];
if(dy < 0) for(int i = first+7; i <= last; i += 7) road[cnt++] = 'A' + ret[i];
}
else if(P[last][1] == P[first][1])
{
if(dx > 0) for(int i = first+1; i <= last; i += 1) road[cnt++] = 'A' + ret[i];
if(dx < 0) for(int i = first-1; i >= last; i -= 1) road[cnt++] = 'A' + ret[i];
}
else
{
int next = first;
int sx = P[last][0] - P[first][0];
int sy = P[last][1] - P[first][1];
while((P[next][0] != P[last][0] || P[next][1] != P[last][1]) && next >= 0 && next <= 27)
{
int tmpx = P[next][0] + dx;
int tmpy = P[next][1] + dy;
int tmpj = judge(sx, sy, tmpx - P[first][0], tmpy - P[first][1]);
if(dx < 0 && dy < 0)
{
if(tmpj < 0) next += 7;
if(tmpj > 0) next -= 1;
if(tmpj == 0) next += 6;
}
if(dx > 0 && dy < 0)
{
if(tmpj < 0) next += 1;
if(tmpj > 0) next += 7;
if(tmpj == 0) next += 8;
}
if(dx > 0 && dy > 0)
{
if(tmpj < 0) next -= 7;
if(tmpj > 0) next += 1;
if(tmpj == 0) next -= 6;
}
if(dx < 0 && dy > 0)
{
if(tmpj < 0) next -= 1;
if(tmpj > 0) next -= 7;
if(tmpj == 0) next -= 8;
}
if(next != 0 && next != 6) road[cnt++] = 'A' + ret[next];
}
}
}
int main()
{
#ifdef BellWind
freopen("12823.in", "r", stdin);
#endif // BellWind
int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d %s", &n, key);
cnt = 0;
memset(road, 0, sizeof(road));
int len = strlen(key);
road[cnt++] = key[0];
for(int l = 0; l+1 < len; l++) findroad(pos[key[l]-'A'], pos[key[l+1]-'A']);
road[cnt] = '\0';
// puts(road);
bool flag = true;
for(int t = 0; t < n; t++)
{
char word[104];
scanf("%s", word);
if(flag)
{
int lenw = strlen(word);
int k, l;
for(l = 0, k = 0; l < cnt && k < lenw; l++) if(word[k] == road[l]) k++;
if(k == lenw)
{
flag = false;
printf("%s\n", word);
}
}
}
if(flag) printf("NO SOLUTION\n");
}
return 0;
}
/**********************************************************************
Problem: 1438
User: 3901140225
Language: C++
Result: AC
Time:44 ms
Memory:2044 kb
**********************************************************************/